How to find elements by attribute namespace in XPath

后端 未结 4 2006
春和景丽
春和景丽 2020-12-05 01:06

I\'m trying to use XPath to find all elements that have an element in a given namespace.

For example, in the following document I want to find the foo:bar

4条回答
  •  难免孤独
    2020-12-05 01:21

    Use:

    //*[namespace-uri()='yourNamespaceURI-here'
       or
        @*[namespace-uri()='yourNamespaceURI-here']
       ]
    

    the predicate two conditions are or-ed with the XPath or operator.

    The XPath expression thus selects any element that either:

    • belongs to the specified namespace.
    • has attributes that belong to the specified namespace.

提交回复
热议问题