xpath Find nodes that have a specific attribute Find nodes by substring matching of an attribute's value


Example

XML

<Galaxy>
    <name>Milky Way</name>
    <CelestialObject name="Earth" type="planet"/>
    <CelestialObject name="Sun" type="star"/>
</Galaxy>

XPATH

/Galaxy/*[contains(@name,'Ear')]

or

//*[contains(@name,'Ear')]

Double quotes can also be used in place of single quotes:

/Galaxy/*[contains(@name, "Ear")]

OUTPUT

<CelestialObject name="Earth" type="planet" />