2
XmlDocument objXmldoc = new XmlDocument();
objXmldoc.Load(txtBrowseFilePath.Text);    
XmlNodeList objxmlNodeList=null;
    objxmlNodeList = objXmldoc.SelectNodes(@"/AppXmlLogWritter/LogData[LogDateTime/text()[starts-with(. , '" + dateTimePickerFromDate.Value.ToString("yyyyMMdd") + "')]]");

DataSet ds = new DataSet();         
ds.ReadXml(objxmlNodeList);

如何将 XmlNodeList 转换为 Xmlstring 以将 xml 数据与数据集绑定

xml文件

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<AppXmlLogWritter>
<LogData>
    <LogID>5678201301161640382918</LogID>
    <LogDateTime>20130116164037</LogDateTime>
    <LogType>Message</LogType>
    <LogFlag>RISLogFlag</LogFlag>
    <LogApplication>BaburaoLogApplication</LogApplication>
    <LogModule>RISLogModule</LogModule>
    <LogLocation>RISLogLocation</LogLocation>
    <LogText>BaburaoLogText</LogText>
  </LogData>
<LogData>
    <LogID>5678201301161640382919</LogID>
    <LogDateTime>20130116164038</LogDateTime>
    <LogType>Warning</LogType>
    <LogFlag>MACLogFlag</LogFlag>
    <LogApplication>MACLogApplication</LogApplication>
    <LogModule>MACLogModule</LogModule>
    <LogLocation>MACLogLocation</LogLocation>
    <LogText>MACLogText</LogText>
  </LogData>
</AppXmlLogWritter>
4

1 回答 1

2

试试这样的功能:

    private string XmlNodeListToString(XmlNodeList nodeList)
    {
        String returnStr = "";
        if (nodeList != null)
        {
            foreach (XmlNode node in nodeList)
            {
                returnStr += node.OuterXml;
            }

        }
        /*
        //I think this is not needed from Dataset.ReadXml
        returnStr = returnStr .Replace("&", "&amp;");
        returnStr = returnStr.Replace("<", "&lt;");
        returnStr = returnStr.Replace(">", "&gt;");
        returnStr = returnStr.Replace("'", "&apos;");
        returnStr = returnStr.Replace("\"", "&quot;");
        */


        return "<Root>"+returnStr+"</Root>";
    }

此外,从您的评论看来,您的文件名很长。

尝试objXmldoc.Load(@txtBrowseFilePath.Text);

或者如果它不成功尝试其他类似前面的文件路径的东西,\\?\ 正如我在这个链接中发现的那样

例如,"\\?\D:\very long path"

于 2013-01-25T09:55:39.983 回答