Article ID: 313828 - Last Review: August 12, 2005 - Revision: 6.2 INFO: Roadmap for Executing XPath Queries in .NET ApplicationsThis article was previously published under Q313828 On This PageSUMMARY This article provides a roadmap to introduce the .NET
Framework namespaces and classes that you can use to programmatically execute
XML Path Language (XPath) queries against Extensible Markup Language (XML)
documents and streams in .NET applications. Roadmap articles provide links to
useful information, including online documentation, Microsoft Knowledge Base
articles, and Microsoft white papers, to help you learn about a Microsoft
product or technology. This article is not an XPath tutorial. This article assumes that you are familiar with the XPath query language and standards. OverviewThe XPath query language is commonly used in XML-based applications to query the contents of an XML document. XPath queries are commonly used in Extensible Stylesheets Language Transformations (XSLT) to locate and to apply XSLT templates to specific nodes in an XML document.XPath queries are also commonly used to locate and to process nodes programmatically in an XML document that match a specified criteria. This article focuses on the programmatic execution of XPath queries in the .NET Framework. QuickStart TutorialsFor more information about how to query with the XPathNavigator and the XpathExpression classes, see the following Microsoft QuickStart tutorials:
How Do I...Navigate XML with the XPathNavigator? http://samples.gotdotnet.com/quickstart/howto/doc/xml/navigatexmldocument.aspx (http://samples.gotdotnet.com/quickstart/howto/doc/xml/navigatexmldocument.aspx) How Do I...Query XML with an XPath expression? http://samples.gotdotnet.com/quickstart/howto/doc/xml/queryxmldocumentxpath.aspx (http://samples.gotdotnet.com/quickstart/howto/doc/xml/queryxmldocumentxpath.aspx) How Do I...Use an XPathExpression class? http://samples.gotdotnet.com/quickstart/howto/doc/xml/xpathexpression.aspx (http://samples.gotdotnet.com/quickstart/howto/doc/xml/xpathexpression.aspx) Programmatically Execute XPath Queries in the .NET FrameworkThe .NET Framework includes the following options to programmatically execute XPath queries in the .NET Framework:
Use the XmlDocument Class to Execute XPath QueriesThe XmlDocument class (which is implemented in the System.Xml namespace) implements the .NET Framework core XML DOM parser. The XML DOM parser complies with the W3C DOM Level 1.0 specifications. Microsoft recommends that you use this parser as the .NET Framework XML parser when you must insert, modify, or delete nodes in an XML document.The XmlDocument class implements the SelectNodes and the SelectSingleNode methods. You can use these methods to specify and to execute XPath queries against XML data that is loaded into the DOM. For additional information about how to use these methods and to see a relevant code sample), click the article number below to view the article in the Microsoft Knowledge Base: 317018
(http://support.microsoft.com/kb/317018/EN-US/
)
HOW TO: Use the System.Xml.XmlDocument Class to Execute XPath Queries in Visual Basic .NET
When you execute XPath queries against XML
documents or streams that define and use custom namespaces, you must use a System.Xml.XmlNamespaceManager object to provide the required namespace resolution and scope
management support. Microsoft Knowledge Base article Q316913 describes how to
use an XmlNamespaceManager object to specify namespaces when you execute the SelectNodes method of the XmlDocument class. The same principle applies when you use the SelectSingleNode method.
For additional information, click the article number below to
view the article in the Microsoft Knowledge Base: 316913
(http://support.microsoft.com/kb/316913/EN-US/
)
HOW TO: Specify Namespaces When You Use an XmlDocument to Execute XPath Queries in Visual Basic .NET
More Information About the System.Xml.XPath NamespaceThe System.Xml.XPath namespace contains the .NET Framework XPath parser and evaluation engine. System.Xml.XPath supports the W3C XML Path Language (XPath) Version 1.0 Recommendation (http://www.w3.org/TR/xpath) .System.Xml.XPath also contains the following classes, which are optimized to programmatically execute XPath queries and to navigate the generated resultsets:
Microsoft Knowledge Base ArticlesFor additional information about how to execute XPath queries by using the classes of the System.Xml.XPath namespace and to see relevant code samples, click the article number below to view the article in the Microsoft Knowledge Base:317069
(http://support.microsoft.com/kb/317069/EN-US/
)
HOW TO: Execute XPath Queries by Using the System.Xml.XPath Classes
When you use the classes of the System.Xml.XPath namespace to execute XPath queries against XML documents or
streams that define and use custom XML namespaces, you must use a System.Xml.XmlNamespaceManager object to provide the required namespace resolution and scope
management support. For additional information about how to use the System.Xml.XmlNamespaceManager object, click the article number below to view the article in the
Microsoft Knowledge Base:
308062
(http://support.microsoft.com/kb/308062/EN-US/
)
HOW TO: Specify Fully Qualified Element Names in XPath Queries by Using Visual Basic .NET
If you write error handling code to catch an XPathException exception when you execute the Select and the Compile methods of the XPathNavigator object, you can more easily identify problems that are caused
specifically by the XPath expressions that you use in your code. For additional
information about how to write code to catch an XPathException exception, click the article number below to view the article in
the Microsoft Knowledge Base:
317108
(http://support.microsoft.com/kb/317108/EN-US/
)
HOW TO: Use the XPathException Class in Visual Basic .NET
The XPathExpression object exposes the AddSort method, which you can use to sort the results of an XPath query
on a specified XML element or attribute.
For additional information about how to use this method and to
see a relevant code sample, click the article number below to view the article
in the Microsoft Knowledge Base: 317084
(http://support.microsoft.com/kb/317084/EN-US/
)
HOW TO: Use the AddSort Method of the XPathExpression Object in Visual Basic .NET
When you use a string to specify the sort key
expression parameter in a call to the AddSort method of the System.Xml.XPath.XPathExpression object, the XML data is not sorted.
316656
(http://support.microsoft.com/kb/316656/EN-US/
)
BUG: Data Not Sorted When You Use Namespace Prefix in String Passed to XPathExpression.AddSort
Guidelines
TroubleshootingIf you experience problems or if you have questions, you can refer to the MSDN newsgroups where you can share your experiences with your peers. You can also use the Microsoft Knowledge Base where you can search for articles about specific issues or contact Microsoft Product Support Services.
MSDN Newsgroups http://msdn.microsoft.com/newsgroups/ (http://msdn.microsoft.com/newsgroups/) Searching the Knowledge Base http://support.microsoft.com/search (http://support.microsoft.com/search) Microsoft Product Support Services http://support.microsoft.com (http://support.microsoft.com/) REFERENCESFor additional information%1,
click the article number%2 below to view the article%2 in the Microsoft
Knowledge Base: 313651
(http://support.microsoft.com/kb/313651/EN-US/
)
INFO: Roadmap for XML in the .NET Framework
| Article Translations
|
Back to the top
