Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何编写只选择非空子级的XPath选择器?_Xpath - Fatal编程技术网

如何编写只选择非空子级的XPath选择器?

如何编写只选择非空子级的XPath选择器?,xpath,Xpath,我想编写一个XPath表达式,用于选择当前元素的所有非空table:table cell子元素。我该怎么做?明白了: table:表格单元格[计数(*)>0] 选择所有 非空表格:表格单元格子项 在XPath1.0中 table:table-cell[node()] 注意:此元素不是空的: <table:table-cell>Something</table:table-cell> 什么 但是表达式table:table cell[count(*)>0]没有选择它,

我想编写一个XPath表达式,用于选择当前元素的所有非空
table:table cell
子元素。我该怎么做?

明白了:

table:表格单元格[计数(*)>0]

选择所有 非空
表格:表格单元格
子项

在XPath1.0中

table:table-cell[node()]
注意:此元素不是空的:

<table:table-cell>Something</table:table-cell>
什么
但是表达式
table:table cell[count(*)>0]
没有选择它,因为它的意思是:所有
table:table cell
chindren至少有一个元素children

您能发布一些示例XML和预期输出吗?哦,对了。在我的情况下,区别其实并不重要,但谢谢你的解释。
table:table cell[count(node())>0]
是否等效?@Eric:Yes。这个表达式是等价的,但要详细得多。需要注意的是,非空节点集的布尔值为true。