Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 解析xml-空元素_C#_Xml - Fatal编程技术网

C# 解析xml-空元素

C# 解析xml-空元素,c#,xml,C#,Xml,我在解析XML时遇到问题,这是我的XML: <Invoice version="6.0.1"> <DocumentType>1</DocumentType> <ID>FV17116113</ID> <InvoiceLines> <InvoiceLine> <UnitPrice>25</UnitPrice> </Invoice

我在解析XML时遇到问题,这是我的XML:

<Invoice version="6.0.1">
   <DocumentType>1</DocumentType>
   <ID>FV17116113</ID>
   <InvoiceLines>
      <InvoiceLine>
         <UnitPrice>25</UnitPrice>
      </InvoiceLine>
      <InvoiceLine>
         <UnitPrice>55</UnitPrice>
      </InvoiceLine>
   </InvoiceLines>
</Invoice>
但我在元素行中没有任何内容。。。。
你知道吗?

我真的不能理解你的问题? 我想您应该从Invoice节点中删除xmlns属性

去掉这个

xmlns="http://isdoc.cz/namespace/2013"
然后,你的代码就可以工作了

  foreach (XmlElement row in xml.DocumentElement.SelectNodes("InvoiceLines/InvoiceLine"))
            {
                Console.WriteLine(row.InnerText);
            }

您的代码应该可以正常工作。你能检查一下什么是
sourcexml
吗?@HHLV-我只加载一个文件*.isdoc…这种格式是标准xml…-请提供一个实际可行的解决方案。如果您正在查找该值,请尝试使用上述InnerText属性。另外,我认为Load方法需要一个带有文件名的字符串。您应该将其更改为LoadXml方法。
sourcexml
是包含XML的字符串,还是磁盘上XML文件的路径?我不这么认为。我可以在我的输出窗口中看到25和55。这是任何在线页面,我可以在哪里上传我的文件结构,您可以对其进行测试?是的,格式正确…我尝试了这个…是否可以将我的文件复制到web上,您可以对此进行检查?
  foreach (XmlElement row in xml.DocumentElement.SelectNodes("InvoiceLines/InvoiceLine"))
            {
                Console.WriteLine(row.InnerText);
            }