如何用xpath排除元素

时间:2014-04-14 20:38:12

标签: xpath

这是我的xpath查询:

//div[contains(@class,"group") and contains(@class,"group-even")]//div[descendant-or-self::text()]

将从以下内容中获取内容:

<div class="service-group">
<div class="group group-even">...</div>
<div class="group">...</div>
</div>

哪个好,但它也需要以下内容:

<div class="service-group">
...
<div id="lastCollectionHours" class="group lastCollectionHours">...</div>
...
</div>

<div class="service-group">
...
<div id="retailHours" class="group group-even retailHours">
    ...
</div>

我想排除这两个div,我该怎么办?

1 个答案:

答案 0 :(得分:0)

排除的基础尚不清楚,但从字面上排除了您指定的两个节点:

div[
    contains(@class, "group") and
    not(
        @id = "retailHours" or
        @id = "lastCollectionHours"
    )
]//...

http://www.xmlplayground.com/YI3Pe4