Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xpath multiple condition on same node

Tags:

c#

xml

xpath

I have a xml structure like below

<?xml version="1.0" encoding="UTF-8"?>
<Result>
   <node>
      <field value="79055_v01" name="Id" />
   </node>
   <node>
      <field value="79055" name="Id" />
   </node>
   <node>
      <field value="79155" name="Id" />
   </node>
   <node>
      <field value="811" name="Id" />
   </node>
   <node>
      <field value="811_v16" name="Id" />
      <field value="811" name="abc" />
   </node>
</Result>

I want to select the which contain the field name 'Id' and the value '811'. What would be the xpath for this

So the correct xpath should return only

<node>
  <field value="811" name="Id" />
</node>

Tried

/Result/node[field/@name='Id' and field/@value='811'] 

but this returns two nodes

like image 428
new user 2018 Avatar asked Mar 26 '26 05:03

new user 2018


1 Answers

If you want to get node that has field with two required attributes, try:

/Result/node[field[@name='Id' and @value='811']] 
like image 164
Andersson Avatar answered Mar 27 '26 18:03

Andersson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!