XPath expression for element based on content of other element withsame parent

I

Ian Wilson

If I have this XML

<response>
<list>
<item>
<message>
<reply>
<something/>
<fee>
<type>A</type>
<amount>22</amount>
</fee>
<fee>
<type>B</type>
<amount>98</amount>
</fee>
<otherthings/>
</reply>
</message>
</item>
</list>
</response>

Is there an XPath expression I can use to get fee amount 98, i.e. the
contents of <amount> where <type> contains "B"?
 
M

Martin Honnen

Ian said:
If I have this XML

<response>
<list>
<item>
<message>
<reply>
<something/>
<fee>
<type>A</type>
<amount>22</amount>
</fee>
<fee>
<type>B</type>
<amount>98</amount>
</fee>
<otherthings/>
</reply>
</message>
</item>
</list>
</response>

Is there an XPath expression I can use to get fee amount 98, i.e. the
contents of <amount> where <type> contains "B"?

That is easy
/response/list/item/message/reply/fee[type = 'B']/amount
 
I

Ian Wilson

Martin said:
Ian said:
If I have this XML

<response>
<list>
<item>
<message>
<reply>
<something/>
<fee>
<type>A</type>
<amount>22</amount>
</fee>
<fee>
<type>B</type>
<amount>98</amount>
</fee>
<otherthings/>
</reply>
</message>
</item>
</list>
</response>

Is there an XPath expression I can use to get fee amount 98, i.e. the
contents of <amount> where <type> contains "B"?


That is easy
/response/list/item/message/reply/fee[type = 'B']/amount

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,008
Messages
2,570,270
Members
46,872
Latest member
Stephendes

Latest Threads

Top