I know I can select nodes by attribute name using
//*[@attribute]
But how do I do it if my attribute is a namespace like bar:resource?
For example:
<foo:creator bar:resource="https://example/john">john</foo:creator>
Pretty much same stuff:
//*[@bar:resource]
This XPath selects all nodes which have @bar:resource attribute. To use this, you need to pass namespace uri and namespace prefix (bar) into your XML/XPath engine/processor.
Alternatively you can use pure XPath (although I don't recommend this):
//*[@*[local-name() = 'resource' and namespace-uri() = 'bar_namespace_uri']]
//*[@*[local-name() = 'resource']] select?//*[@*[local-name() = 'resource']] doesn't check namespace of the attribute, i.e. resource="" and bar:resource="" both have local-name resource.//*[@bar:resource] you also need to check namespace of the attribute, e.g.: //*[@*[local-name() = 'resource' and namespace-uri() = 'bar_namespace_uri']]. I don't recommend this approach in terms of maintenance and flexibility: imagine you have many queries which all need to check namespace. This means in every query you need to specify namespace uri, which leads to code duplication, potential errors, etc.