I have a following XML:
I have filled a DropdownList with all the titles. Now how can I get the author and price of particular title when selected in the dropdownlist through XPath and C#.
I am using following method:
but this is not helping. It returns Full InnerXml of the file.
Code:
<?xml version="1.0" encoding="utf-8" ?> <catalog> <cd country="USA"> <title>ABCD</title> <author>yash</author> <price>10.90</price> </cd> <cd country="UK"> <title>XYZ</title> <author>John</author> <price>10.0</price> </cd> <cd country="USA"> <title>GreatHits</title> <author>yash</author> <price>9.90</price> </cd> </catalog>
I am using following method:
Code:
string fileName="Catalog.xml";
string title= DropDownList1.SelectedItem.ToString();
XmlDocument xdoc=new XmlDocument();
xdoc.Load(@"C:\Inetpub\Wwwroot\Xpath1\" +fileName);
string price= xdoc.SelectSingleNode("/catalog/cd/price[title='" + title "']").Value;