Wednesday, April 30, 2014

Easy way to search attribute value in XML

If there are many attributes with same name like below
<root>
      <node name="n1" path="1.jpg"/>
      <node name="n2" path="2.jpg"/>
      <node name="n3" path="3.jpg"/>
      <node name="n4" path="4.jpg"/>
</root>

Then if you want to search node n3 path value in easy method then use the following method

XmlDocument doc = new XmlDocument();
doc.Load(xmlPath);
doc.SelectSingleNode("/root/node[@name='n3']").Attributes["path"].Value

No comments:

Post a Comment