Mega Code Archive

 
Categories / C# / XML
 

Selects the first XmlNode that matches the XPath expression

using System; using System.IO; using System.Xml; public class Sample {   public static void Main() {     XmlDocument doc = new XmlDocument();     doc.Load("booksort.xml");     XmlNode book;     XmlNode root = doc.DocumentElement;     book=root.SelectSingleNode("descendant::book[author/last-name='A']");     book.LastChild.InnerText="15.95";     doc.Save(Console.Out);       } }