using System;
using System.Xml.XPath;
class MainClass{
static void Main(string[] args) {
XPathDocument xpathDocument = new XPathDocument("sample.xml");
XPathNavigator xpathNavigator = xpathDocument.CreateNavigator();
XPathNodeIterator xpathNodeIterator = xpathNavigator.Select("//companies/cell-phone[last()]");
int i = 0;
Console.Out.WriteLine(xpathNodeIterator.Count);
while (xpathNodeIterator.MoveNext()) {
Console.Out.WriteLine((++i) + ". Name: <" + xpathNodeIterator.Current.Name + ">. Value: " + xpathNodeIterator.Current.Value + ".");
}
}
}
|