Korben
Korben

Reputation: 734

XPath select nodes with attribute names

Suppose We have a XML document given as

<MyDocument>
<Pages>
    <Page>
        <Para>
            <Word show="yes" wo="2">Some</Word>
            <Word>People</Word>
        </Para>
    </Page>
    <Page>
        <Para>
            <Word>Some</Word>
            <Word show="yes">Other</Word>
            <Word show="yes" wo="1">People</Word>
        </Para>
    </Page>
</Pages>
</MyDocument>

how can we find all the Word nodes with both attribute 'show' and 'wo'? I tried XPath //[@show] | //[@wo] but this expression selects node with @show as well. and //*[@show @wo] is not legal expression.

thanks

Upvotes: 3

Views: 2215

Answers (1)

alecxe
alecxe

Reputation: 473753

how can we find all the Word nodes with both attribute 'show' and 'wo'?

Use and:

//Word[@show and @wo]

Or, you can also have multiple conditions in separate square brackets:

//Word[@show][@wo]

Upvotes: 8

Related Questions