xpath

Namespaces

Remarks#

XPath 1.0 doesn’t have the concept of a default namespace.

Also, the namespace prefixes defined in the original XML document do not affect XPath - namespace prefixes have to be explicitly registered with the XPath provider, otherwise prefixes can’t be used at all in the XPath expression.

Namespace aware functions

<root xmlns="https://test/">
    <element xmlns:example="https://foobar/">
        <example:hello_world attribute="another example" />
    </element>
</root>

The expression /root will return nothing, because there is no non-namespaced element called root at the root level of the document. However, The following will return the <root xmlns="https://test/"> element.

/*[namespace-uri() = 'https://test/' and local-name() = 'root']

This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow