我如何使用分组条件从 XML 中获取值?
How I fetching value from XML with grouping conditions?
我想在某些条件下从 XML 中获取属性值。我不知道这组值是如何在 XPATH 条件下检查的。
下面是我的XML格式:
<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>
我想要一个不匹配的值。条件是//CYAccountHide/fldActNumber/@Value != //person/@address
但是那个条件不成立。
基本上在我的 XML 中,我的 //CYAccountHide/fldActNumber/@Value
属性值为 502100,502200,502201
,//person/@address
属性值为 502100,502200
。我想借助 xpath 的价值只是 502201
如果只验证一个值,那么 //CYAccountHide/fldActNumber/@Value != '502100' 这个条件可行,但我想用 XML 标签验证一组值。
我想我现在已经明白你需要什么了。使用以下 XPath 表达式
//CYAccountHide/fldActNumber/@Value[not(. = //person/@address)]
转换为
//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.
结果将是
Value="502201"
我想在某些条件下从 XML 中获取属性值。我不知道这组值是如何在 XPATH 条件下检查的。
下面是我的XML格式:
<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>
我想要一个不匹配的值。条件是//CYAccountHide/fldActNumber/@Value != //person/@address
但是那个条件不成立。
基本上在我的 XML 中,我的 //CYAccountHide/fldActNumber/@Value
属性值为 502100,502200,502201
,//person/@address
属性值为 502100,502200
。我想借助 xpath 的价值只是 502201
如果只验证一个值,那么 //CYAccountHide/fldActNumber/@Value != '502100' 这个条件可行,但我想用 XML 标签验证一组值。
我想我现在已经明白你需要什么了。使用以下 XPath 表达式
//CYAccountHide/fldActNumber/@Value[not(. = //person/@address)]
转换为
//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.
结果将是
Value="502201"