gpt4 book ai didi

java - XPATH使用条件过滤不同内部路径中的元素

转载 作者:行者123 更新时间:2023-11-30 02:37:48 26 4
gpt4 key购买 nike

团队,我正在学习多个 XPATH 教程,但无法使用一个 XPathExpression 实现以下期望。

如何获取 PostpaidInformation --> AccountNumber=AC-12 的 ActiveValue 和日期值 ..?

<params>
<param>
<value>
<struct>
<member>
<name>PrepaidInformation</name>
<value>
<struct>
<member>
<name>activationStatus</name>
<value>
<boolean>1</boolean>
</value>
</member>
</struct>
</value>
</member>
<member>
<name>MixedInformation</name>
<value>
<struct>
<member>
<name>activationStatus</name>
<value>
<boolean>0</boolean>
</value>
</member>
</struct>
</value>
</member>
<member>
<name>PostpaidInformation</name>
<value>
<array>
<data>
<value>
<struct>
<member>
<name>ActiveValue</name>
<value>
<string>60</string>
</value>
</member>
<member>
<name>Date</name>
<value>
<string>20170225T12:00:00</string>
</value>
</member>
<member>
<name>AccountNumber</name>
<value>
<i4>AC-12</i4>
</value>
</member>
</struct>
</value>
<value>
<struct>
<member>
<name>ActiveValue</name>
<value>
<string>23</string>
</value>
</member>
<member>
<name>Date</name>
<value>
<string>20170225T12:00:00</string>
</value>
</member>
<member>
<name>AccountNumber</name>
<value>
<i4>AC-13</i4>
</value>
</member>
</struct>
</value>
</data>
</array>
</value>
</member>
</struct>
</value>
</param>
</params>

注意,我必须匹配 PostpaidInformation,然后匹配 AccountNumber = AC-12。如果匹配则打印有关该帐户的所有信息。

也许我需要的是//methodResponse/params/param/value/struct/member/name[text()=\"PostpaidInformation\"]遍历其中的所有帐户,直到找到 AccountNumber=AC-12 ,如果找到则从 member/value 退出一级到达<struct>迭代所有 <member>在该结构内部。

预期输出是下面要遍历的NodeSet。

                                    <member>
<name>ActiveValue</name>
<value>
<string>60</string>
</value>
</member>
<member>
<name>Date</name>
<value>
<string>20170225T12:00:00</string>
</value>
</member>
<member>
<name>AccountNumber</name>
<value>
<i4>AC-12</i4>
</value>
</member>

实际答案

安德森是

//member/name[text()="PostpaidInformation"]/following-sibling:: 
value/array/data/value/struct[member[name="AccountNumber"]/value/i4="AC-12"]

har07 是

//member[name='PostpaidInformation']//struct[member[name='AccountNumber' and value/i4='AC-12']]/member

最佳答案

你能尝试一下吗:

//member/name[text()="PostpaidInformation"][1]/following-sibling::value/array/data/value/struct/member

这个XPath应该返回 3 member节点:

<member>
<name>ActiveValue</name>
<value>
<string>60</string>
</value>
</member>
<member>
<name>Date</name>
<value>
<string>20170225T12:00:00</string>
</value>
</member>
<member>
<name>AccountNumber</name>
<value>
<i4>AC-12</i4>
</value>
</member>

如果你想检索<struct>包含那些 3 <member> :

//member/name[text()="PostpaidInformation"]/following-sibling::value/array/data/value/struct[member[name[.="AccountNumber"]/following-sibling::value/i4="AC-12"]]

关于java - XPATH使用条件过滤不同内部路径中的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42622751/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com