我使用三种 XML 文件:
A 型:
<?xml version="1.0" encoding="UTF-8"?>
<nfeProc versao="2.00" xmlns="http://www.portalfiscal.inf.br/nfe">
</nfeProc>
B 型:
<?xml version="1.0" encoding="UTF-8"?>
<cancCTe xmlns="http://www.portalfiscal.inf.br/cte" versao="1.04">
</cancCTe>
C 型:]
<?xml version="1.0" encoding="UTF-8"?>
<cteProc xmlns="http://www.portalfiscal.inf.br/cte" versao="1.04">
</cteProc>
我尝试使用此代码读取第一个节点:
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(@"C:\crruopto\135120068964590_v01.04-procCTe.xml");
XmlNodeList ml = xmlDoc.GetElementsByTagName("*");
XmlElement root = xmlDoc.DocumentElement;
exti = root.ToString();
但不返回任何我想读取第一个节点的内容,需要知道文件是 nfeProc 、canCTE 还是 cteProc 第二个问题是我如何从同一标签中的“value”中获取值???
谢谢
最佳答案
来自this帖子:
//Root node is the DocumentElement property of XmlDocument
XmlElement root = xmlDoc.DocumentElement
//If you only have the node, you can get the root node by
XmlElement root = xmlNode.OwnerDocument.DocumentElement
关于c# - 从 XML 中读取第一个根节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15690354/