0

我想选择所有 b where c2attr > 5on c2 = text2。在 Xpath 中,我写道:

a/b[c2 = text2 and c2attr >5]

但是,它并没有给我两个满足时的条件c2=text2c2attr >5。它给了我每个具有c2attr >5. 我应该如何写才能正确选择
b?

例如:

<a>
    <b>
        <c1>c1 text</c1>
        <c2 c2attr="3">text1</c2>
        <c2 c2attr="8">tex2</c2>
        <c2 c2attr="50">text3</c2>
    </b>
    <b>
        <c1>c1 text</b1>
        <c2 c2attr="1">text4</c2>
        <c2 c2attr="6">tex2</c2>
        <c2 c2attr="10">text1</c2>
    </b>
</a>

非常感谢!

4

1 回答 1

0

您需要更改c2 = text2为,c2 = 'text2'因为您正在比较字符串,并添加属性说明符@c2attr如下所示:

a/b[c2[text() = 'tex2'  and @c2attr > 5]]

此外,您的 XML 无效,不确定是否拼写错误,但您有一个<c1>用 关闭的节点<b1>,并且它也不包含带有“text2”的文本,它缺少最后一个“t”。

于 2013-02-14T15:37:30.333 回答