XPath expressions can include namespaces. Namespace resolution is supported using the XmlNamespaceManager. If the XPath expression includes a prefix, the prefix and namespace URI pair must be added to the XmlNamespaceManager.

Note

If the XPath expression does not include a prefix, it is assumed that the namespace URI is the empty namespace. If your XML includes a default namespace, you must still add a prefix and namespace URI to the XmlNamespaceManager; otherwise, you will not get a node selected. For more information, see Select Nodes Using XPath Navigation.

A common issue when formulating XPath expressions is how to include a single quote (') or double quote (") in the expression. If you have to search for a value that includes a single quote, you must enclose the string in double quotes. If you need to search for a value that includes a double quote, you must enclose the string in single quotes.

<?xmlversion="1.0"?><!-- A fragment of a book store inventory database --><bookstorexmlns:bk="urn:samples"><bookgenre="novel"publicationdate="1997"bk:ISBN="1-861001-57-8"><title>Pride And Prejudice</title><author><first-name>Jane</first-name><last-name>Austen</last-name></author><price>24.95</price></book><bookgenre="novel"publicationdate="1992"bk:ISBN="1-861002-30-1"><title>The Handmaid's Tale</title><author><first-name>Margaret</first-name><last-name>Atwood</last-name></author><price>29.95</price></book><bookgenre="novel"publicationdate="1991"bk:ISBN="1-861001-57-6"><title>Emma</title><author><first-name>Jane</first-name><last-name>Austen</last-name></author><price>19.95</price></book><bookgenre="novel"publicationdate="1982"bk:ISBN="1-861001-45-3"><title>Sense and Sensibility</title><author><first-name>Jane</first-name><last-name>Austen</last-name></author><price>19.95</price></book></bookstore>