如何使用XML读取技术按特定值计算元素 [英] How to count elements by particular value using XML reading techniques
本文介绍了如何使用XML读取技术按特定值计算元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想计算所有
<Child>
节点值
type="Note"
例子
Example
<Child type="Note"></Child>
<Child type="Pen"></Child>
<Child type="Note"></Child>
<Child type="Ruler"></Child>
<Child type="Note"></Child>
如何计算节点< child>具有值类型=注意。
如何使用XML函数执行此操作
How to count the node <child> having Value type="Note".
How to do this with XML functions
推荐答案
请参阅到链接:
选择属性值的XML节点[C#] [ ^ ]
然后你可以使用Count()方法。
祝你好运,
OI
Please refer to the link:
Select XML Nodes by Attribute Value [C#][^]
Then you can use Count() method.
Good luck,
OI
你好!
我认为这就是你要找的东西。
Hello!
I think this is what you are looking for.
XmlDocument xml = new XmlDocument();
int count;
xml.LoadXml(str);
XmlNodeList xnList = xml.SelectNodes("/{ParentNode}/Child[@type='Book']");
count = xnList.count;
你也可以参考这个http://www.csharp-examples.net/xml-nodes-by-attribute-value/ [ ^ ]
Hitesh Varde
高级软件工程师
you can also refer this http://www.csharp-examples.net/xml-nodes-by-attribute-value/[^]
Hitesh Varde
Sr. Software Engineer
这篇关于如何使用XML读取技术按特定值计算元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文