【发布时间】:2020-07-12 23:40:25
【问题描述】:
我需要读取一个 Xml 文件,并且我正在尝试计算文件中特定标签的数量。我的问题是同一个标签在其他标签外面和里面时代表不同的东西。我能够获得标签的总数,但我需要找到指定标签内的标签计数。
(我通过使用 XmlNodeList nodeList = xmlDoc.DocumentElement.GetElementsByTagName("cac:AllowanceCharge"); 找到总 cac:AllowanceCharge 标签)
要查找我尝试使用的“cac:InvoiceLine”标签内的“cac:AllowanceCharge”标签:
XmlNodeList elemList = root.GetElementsByTagName(@"//cac:InvoiceLine/cac:AllowanceCharge");
XmlNodeList elemList = root.GetElementsByTagName(@"//InvoiceLine/AllowanceCharge");
XmlNodeList elemList = root.GetElementsByTagName(@"cac:InvoiceLine/cac:AllowanceCharge");
如果有人能告诉我正确的语法,我将不胜感激。谢谢。
【问题讨论】:
标签: c# xml xmldocument