html - XPath选择不只有一个特定子节点的节点?

标签 html xml xpath

<div>
  <p>case a</p> # only has a text node, selected
  <p>case <a>b</a></p> # has a text node and an a node, selected
  <p><a>case c</a></p> # only has an a node, not selected
</div>


有没有办法选择不仅具有p节点(即a<p>case a</p>,但没有<p>case <a>b</a></p>)的<p><a>case c</a></p>节点。

最佳答案

这个XPath

//p[not(a) or node()[not(self::a)]]


将选择所有缺少p子元素或子节点不是aa元素,这等效于选择不仅具有p子元素的a元素,

<p>case a</p>
<p>case <a>b</a></p>


按照要求。

关于html - XPath选择不只有一个特定子节点的节点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52377776/

相关文章:

javascript - 每隔一秒在 javascript 中显示和隐藏元素

jquery - 将 xPath 转换为 jQuery 选择器

c# XmlDocument SelectNodes 不返回节点

node.js - 使用 WebdriverJS 选择父元素

包含动态图像的 HTML 按钮 - 调整大小

html - 带有居中 Logo 的多行导航栏

.net - 滥用 XmlReader ReadSubtree()

xml - XSL : Copy Attributes That Match A Whitelist

android - ScrollView 不工作(它不滚动布局)

javascript - 将用 ng-repeat 填充的复选框拆分为列?