Posts

Showing posts from January, 2011

XML Select Single Node

Ref http://msdn.microsoft.com/en-us/library/h0hw012b.aspx <pre> <bookstore xmlns="http://www.lucernepublishing.com"> <book> <title>Pride And Prejudice</title> </book> </bookstore> </pre> XmlDocument doc = new XmlDocument(); doc.Load( "booksort.xml" ); //Create an XmlNamespaceManager for resolving namespaces. XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable); nsmgr.AddNamespace( "bk" , "urn:samples" ); //Select the book node with the matching attribute value. XmlNode book; XmlElement root = doc.DocumentElement; book = root.SelectSingleNode( "descendant::book[@bk:ISBN='1-861001-57-6']" , nsmgr); Console.WriteLine(book.OuterXml);