xpath 用类排除某些子元素 [英] xpath exclude certain child element with class
问题描述
我有一个 html 结构,例如在简化版本中可能如下所示.我想从 xpath 内容中排除与 yarpp 相关的 div.这是我目前正在使用的:
//div[@class='entry-content']
如何排除与 yarpp 相关的 div?
html 结构
<div class="yarpp-related">
XPath 用于选择,而不是操作.您可以选择 XML 文档中存在的节点,但不能转换这些节点.
就您而言,如果您的 XML 文档包含此节点,
<div class="yarpp-related">
您可以通过 //div[@class='entry-content']
选择 entry-content
div
,但是选择的节点将出现在源 XML 中,即 with 子 yarpp-related
div
节点.
如果要操作或转换通过 XPath 选择的节点(以排除其子元素),则必须使用托管语言(XSLT、Python、Java、C# 等)来操作选择.
I have a html structure which for instance could look like below in a simplified version. I want to exclude the yarpp-related div from the xpath content. Here is what i'm using at the moment:
//div[@class='entry-content']
How can i exlude the yarpp-related div?
html structure
<div class="entry-content">
<div class="yarpp-related">
</div>
</div>
XPath is for selection, not manipulation. You can select nodes as they exist in an XML document, but you cannot transform those nodes.
In your case, if your XML document includes this node,
<div class="entry-content">
<div class="yarpp-related">
</div>
</div>
you can select the entry-content
div
via //div[@class='entry-content']
, but the selected node will appear as it appears in the source XML, that is, with the child yarpp-related
div
node.
If you want to manipulate or transform a node selected via XPath (to exclude its children elements) you'll have to use the hosting language (XSLT, Python, Java, C#, etc) to manipulate the selection.
这篇关于xpath 用类排除某些子元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!