xpath Find nodes with a specific attribute value


Example

XML

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

XPATH

/Galaxy/*[@name='Sun']

or

//*[@name='Sun']

OUTPUT

<CelestialObject name="Sun" type="star" />