Hauke
Hauke

Reputation: 1465

XPath Expression for parent element

looked in some articles about this topic, but they all kind of differ to what I am trying to get.

My example XML file:

<AdditionalInformations>
    <AdditionalInformation>
        <Codes>
            <Code type="own">AAA</Code>
            <Code type="foreign">ZZZ</Code>         
        </Codes>
        <Value>MyValue</Value>
    </AdditionalInformation>
    <AdditionalInformation>
        <Codes>
            <Code type="foreign">BBB</Code>
        </Codes>
        <Value>2173.123</Value>
    </AdditionalInformation>
    <AdditionalInformation>
        <Codes>
            <Code type="own">CCC</Code>
        </Codes>
        <Value>true</Value>
    </AdditionalInformation>
</AdditionalInformations>

Now I what the xPath to get "MyValue". The requirements are the following:

I tried this expression:

/AdditionalInformations/AdditionalInformation/[Codes/Code[@type="own"]="AAA"]

but I am not sure how to get to the value-element from there.

Thanks for your help Hauke

Upvotes: 0

Views: 162

Answers (1)

Gilles Qu&#233;not
Gilles Qu&#233;not

Reputation: 185075

Try this xpath :

'//Codes/Code[@type="own" and text() = "AAA"]/../../Value/text()'

Note

..

means parent node

Upvotes: 1

Related Questions