Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

XPath Param Value Is Not Evaluating In Expression

The @Value=’1′ Does not seem to be evaluating in this expression below as it returns both nodes of SEventData instead of only one that has a @Value of ‘1’. What am I missing?

Source:

<CData>
<SData SKey="006" >

<SEventData SEventOID="UNS" SEventRepeatKey="2">
<FData FOID="REQUIRED" FRepeatKey="1">
<ItemGroupData ItemGroupOID="REQUIRED" ItemGroupRepeatKey="0" 
TransactionType="Upsert">
<ItemData ItemOID="REQ" Value="0"  />
</ItemGroupData>
</FData>
</SEventData>

<SEventData SEventOID="UNS" SEventRepeatKey="3">
<FData FOID="REQUIRED" FRepeatKey="1">
<ItemGroupData ItemGroupOID="REQUIRED" ItemGroupRepeatKey="0" 
TransactionType="Upsert">
<ItemData ItemOID="REQ" Value="1"  />
</ItemGroupData>
</FData>
</SEventData>

</SData>
</CData>

with expression

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

//CData[.//SData[@SKey='006']/SEventData/FData/ItemGroupData/ItemData[@ItemOID='REQ' and @Value='1']]//SEventData    

returns both instead of one

Element='<SEventData SEventOID="UNS" SEventRepeatKey="2">
  <FData FOID="REQUIRED" FRepeatKey="1">
     <ItemGroupData ItemGroupOID="REQUIRED"
                 ItemGroupRepeatKey="0"
                 TransactionType="Upsert">
        <ItemData ItemOID="REQ" Value="0"/>
     </ItemGroupData>
  </FData>
</SEventData>'
Element='<SEventData SEventOID="UNS" SEventRepeatKey="3">
  <FData FOID="REQUIRED" FRepeatKey="1">
     <ItemGroupData ItemGroupOID="REQUIRED"
                 ItemGroupRepeatKey="0"
                 TransactionType="Upsert">
        <ItemData ItemOID="REQ" Value="1"/>
     </ItemGroupData>
  </FData>
</SEventData>'

>Solution :

You can use this XPath in order to locate what you are looking for:

//SEventData[.//FData/ItemGroupData/ItemData[@ItemOID='REQ' and @Value='1']]

Your current XPath expression returns the root node //CData containing in it the following condition: .//SData[@SKey='006']/SEventData/FData/ItemGroupData/ItemData[@ItemOID='REQ' and @Value='1'].
So yes, //CData has inside it the condition as above and when you trying to locate //SEventData inside that //CData it returns you both //SEventData nodes.
What you should do here is to locate //SEventData node itself based on your condition as I wrote at the beginning:

//SEventData[.//FData/ItemGroupData/ItemData[@ItemOID='REQ' and @Value='1']]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading