2013-01-25 60 views
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數據如何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> 
+0

請添加一些示例xml,其中應執行選擇節點 – iltzortz

+0

我已添加.......... – John

+0

好的沒有什麼。似乎是一個長文件路徑名稱問題。再次檢查我的回答結束 – iltzortz

回答

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);

,或者如果它不成功 嘗試其他的東西像\\?\前面的文件路徑,因爲我在這個link

例如,"\\?\D:\very long path"發現。

+0

你的解決方案是正確itzortz但讓我錯誤路徑非法字符 – John

+0

我已經嘗試node.ParentNode.OuterXml;但也。 – John

+0

指定的路徑,文件名或這兩者太長。完全限定的文件名必須少於260個字符,且目錄名稱必須少於248個字符。 – John