Using XPathDocument in XPath Queries

Don’t use the XmlDocument class if you are going to work with XPath queries. .NET has its own class for this purpose called XPathDocument, which does not run any validation checking. When using XPath, avoid using // to reduce the search, because // searches the complete document.

XPathDocument Doc = new XPathDocument(FileName);XPathNavigator nav = Doc.CreateNavigator();XPathNodeIterator Iterator = nav.Select("/bookstore/book");while (Iterator.MoveNext()){    Console.WriteLine(Iterator.Current.Name);}
Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: