Select xml node by other node
Posted by Tihomir Ivanov on 15 December 2008 18:01
Rating: 0.00
In this article I'll try to explain some common xml isue. Let's look at the example:
we have some xml file (list.xml):
<?xml version="1.0" encoding="utf-8" ?>
<Root>
<Item>
<Title>AspNetSource.com</Title>
<ID>1</ID>
</Item>
<Item>
<Title>dev-the-web.com</Title>
<ID>2</ID>
</Item>
</Root>
and we want to select Title of this Item which ID is 2. Follows the code:
XmlDocument xmlDocument = new XmlDocument();
XmlNode xmlDocument.Load(Server.MapPath("~") + "App_Data\\list.xml");
xmlNode = xmlDocument.SelectSingleNode("Root/Item[ID='2']");
string OUR_TEXT = xmlNode["Title"].InnerText;
That's all. Happy Coding :)
Comments:
No comments yet.