Mega Code Archive

 
Categories / C# / XML
 

XPathNavigator SelectSingleNode selects a single node in XPathNavigator using XPath query

using System; using System.Linq; using System.Xml; using System.Xml.Linq; using System.Collections; using System.Collections.Generic; using System.Xml.XPath; public class MainClass{    public static void Main(){                    XPathDocument document = new XPathDocument("domainBooks.xml");       XPathNavigator navigator = document.CreateNavigator();              XmlNamespaceManager manager = new XmlNamespaceManager(navigator.NameTable);       manager.AddNamespace("bk", "http://www.domain.com/books");              XPathNavigator node = navigator.SelectSingleNode("//bk:title", manager);       Console.WriteLine(node.InnerXml);    } }