xpath

Finding elements containing specific attributes

Find all elements with a certain attribute

Imagine the following XML:

<root>
    <element foobar="hello_world" />
    <element example="this is one!" />
</root>
/root/element[@foobar]

and will return the <element foobar="hello_world" /> element.

Find all elements with a certain attribute value

Imagine the following XML:

<root>
    <element foobar="hello_world" />
    <element example="this is one!" />
</root>

The following XPath expression:

/root/element[@foobar = 'hello_world']

will return the <element foobar="hello_world" /> element.

double quotes can also be used:

/root/element[@foobar="hello_world"]

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