在特殊的 xml 结构中选择具有 name 属性 name 的元素 [英] select elements with the name attribute name in special xml structure
本文介绍了在特殊的 xml 结构中选择具有 name 属性 name 的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是我的 xml 文档的结构.我只想先取每个节点的值
然后将它与给定的值进行比较.但是我不知道如何在 c# 中使用 xml selectnodes 定位每个节点的 <attribute name="a">
.谷歌搜索没有显示任何有效的解决方案.
below is the structure of my xml document. I just want to first take the value of every node <attribute name="a">
then make a comparison of it with a given value. However I don't how to locate <attribute name="a">
of each node using xml selectnodes in c#. Google searches don't show any working solutions.
<nodes>
<node name = "node1">
<attribute name="a">This is node1 a</attribute>
<attribute name="b">This is node1 b</attribute>
</node>
<node name = "node2">
<attribute name="a">This is node2 a</attribute>
<attribute name="b">This is node2 b</attribute>
</node>
...
</nodes>
推荐答案
假设您问题中的 XML 标记代表您的整个文档,您可以这样做:
Assuming the XML markup in your question represents your whole document, you can do:
XmlNodeList attrElements
= yourDocument.SelectNodes("/nodes/node/attribute[@name='a']");
这篇关于在特殊的 xml 结构中选择具有 name 属性 name 的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文