<valuta category ="HRK">
<value>25value>
<name>25name>
valuta>
<valuta category ="HRK">
<value>5value>
valuta>
<valuta category ="EUR">
<value>25value>
<name>25name>
valuta>
<valuta category ="EUR">
<value>5value>
<name>5name>
valuta>
I would like to get data for category "EUR" ?
David AzzopardiPosted Jul 16, 2009, 5:06 AM
Try something like this:
string fileName = @"C:\data.xml";
XPathDocument doc = new XPathDocument(fileName);
XPathNavigator nav = doc.CreateNavigator();
// xpath: //valuta[@category='EUR']/value
// This returns each value node where category="EUR"
// xpath: //valuta[@category='EUR']/name
// This returns each name node where category="EUR"
// xpath: //valuta[@category='EUR']
// This returns each valuta node with children where category="EUR"
string xpath = "//valuta[@category='EUR']/value";
XPathExpression expr = nav.Compile(xpath);
XPathNodeIterator iterator = nav.Select(expr);
while (iterator.MoveNext())
{
Console.WriteLine(iterator.Current.InnerXml);
}
Cheers,
Dave