Jeet Bhatt
Jeet Bhatt

Reputation: 778

How I fetching value from XML with grouping conditions?

I want to fetching attribute value from XML with some conditions. I did not know how the group of values check in XPATH condition.

Below is my XML format:

<TTIDCData>
   <CYAccountHide HideTable="False">
      <fldAccountType Value="55" HideField="False" PrintValue="55" Description=""/>
      <fldActNumber Value="502100" HideField="False" PrintValue="502100"/>
   </CYAccountHide>
   <CYAccountHide HideTable="False">
      <fldAccountType Value="55" HideField="False" PrintValue="55" Description=""/>
      <fldActNumber Value="502200" HideField="False" PrintValue="502200"/>
   </CYAccountHide>
   <CYAccountHide HideTable="False">
      <fldAccountType Value="55" HideField="False" PrintValue="55" Description=""/>
      <fldActNumber Value="502200" HideField="False" PrintValue="502200"/>
   </CYAccountHide>
   <CYAccountHide HideTable="False">
      <fldAccountType Value="55" HideField="False" PrintValue="55" Description=""/>
      <fldActNumber Value="502222" HideField="False" PrintValue="502200"/>
   </CYAccountHide>
   <person name="blair" address="502100"/>
   <person name="blair" address="502200"/>
   <person name="blair" address="502205"/>
   <person name="blair" address="502200"/>
</TTIDCData> 

I want to value which is not match. Conditions is //CYAccountHide/fldActNumber/@Value != //person/@address

But that condition does not work.

Basically in my XML I have a value for //CYAccountHide/fldActNumber/@Value this attribute is 502100,502200,502201 and for //person/@address attribute have value is 502100,502200. And I want to value with help of xpath is only 502201

If verify only one value then //CYAccountHide/fldActNumber/@Value != '502100' this condition is work but I want verify group of value with that XML tag.

Upvotes: 1

Views: 64

Answers (1)

Mathias M&#252;ller
Mathias M&#252;ller

Reputation: 22617

I think I have understood what you need now. Use the following XPath expression

//CYAccountHide/fldActNumber/@Value[not(. = //person/@address)]

which translates to

//CYAccountHide/fldActNumber/@Value       Select all attributes named "Value" of
                                          elements "fldActNumber" that themselves are
                                          children of "CYAccountHide" elements.
[not(. = //person/@address)]              but only return them if there is no "person"
                                          element anywhere in the document that has an
                                          "address" attribute with the same value as
                                          the "Value" attribute.

and the result will be

Value="502201"

Upvotes: 2

Related Questions