xpath来获取与父项具有相同标签名称的子项

我的要求是获取具有相同父名称的子标记的属性值。 以下是类似的XML结构:

<A>
    <B ID="id">
        <B parentID="id" .. other attributes>
        <B parentID="id" .. other attributes>
        <B parentID="id" .. other attributes>
        <B parentID="id" .. other attributes>
    </B>
</A>

我希望获取父B标签下所有子B标签的属性值。

谢谢

pacheco 回答:xpath来获取与父项具有相同标签名称的子项

知道了。

xpath应该是: A/B/B/*[@parent_Id="id"]/@id

,

返回与父元素名称相同的所有元素的XPath

//*[name()=name(..)]
本文链接:https://www.f2er.com/3140139.html

大家都在问