尝试找出与XPATH
或header
内的所有元素匹配的header
。我们假设可以通过三个条件检测标题:
header
例如。 <header><div.....></header>
id
,其中包含字符串“header”class
,其中包含字符串“header”我的xpath://*[not(ancestor::header)] and //*[not(ancestor::*[contains(@id,"header")])] and //*[not(ancestor::*[contains(@class,"header")])]
不正确。
修改
这应该匹配header
内的所有链接:
//*[ancestor::*[contains(@id,"header") or contains(@class,"header") or header]]
现在我想获得除了这些之外的所有元素。
你知道怎么做吗?
答案 0 :(得分:2)
单独评估原始XPath中的每个表达式,测试XML文档中是否存在满足这些条件的元素,并返回boolean()
。
现在你已经将谓词组合起来选择你不想要的特定元素,你只需要否定测试:
//*[not(ancestor-or-self::header) and
not(ancestor::*[contains(@id,"header") or contains(@class,"header")])
]