Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.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

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
Xml 无法匹配XPath中祖先的以下节点_Xml_Xpath - Fatal编程技术网

Xml 无法匹配XPath中祖先的以下节点

Xml 无法匹配XPath中祖先的以下节点,xml,xpath,Xml,Xpath,我有这样一个XML: <table> <tr class="mergedrow"> <th scope="row"><a href="https://en.wikipedia.org/wiki/Telephone_numbers_in_Austria" title="Telephone numbers in Austria">Area code</a></th> <td>07236</td> <

我有这样一个XML:

<table>
<tr class="mergedrow">
<th scope="row"><a href="https://en.wikipedia.org/wiki/Telephone_numbers_in_Austria" title="Telephone numbers in Austria">Area code</a></th>
<td>07236</td>
</tr>
</table>

07236
我想知道区号:07236。 到目前为止,我所做的是将“”节点与以下内容匹配: //*[text()=“区号”]

现在我需要得到祖先节点的兄弟节点,即节点。 我选择直接在文本上匹配的原因是因为表格很大,有数百行

我尝试了//*[text()=“Area code”]/../祖先::th以至少匹配祖先 还有//*[text()=“区号”]/../following::td。它们都不起作用

我是XPath的新手,如果答案显而易见,我很抱歉。

这个XPath

//th[normalize-space() = 'Area code']/following-sibling::td/text()

将根据请求选择
th
后面
td
元素的
“07236”
文本节点子节点,其空间规范化字符串值为
“区号”

我找到了它。我正在使用KNIME,这是一种数据分析工具,它执行可以做各种事情的节点。在执行XPath节点时,我在前面的注释中编写的名称空间存储在“dns”下。因此,我的最后一个XPath表达式是://dns:[text()=“Area code”]/../following sibling::dns:td.

我同意它适用于我给出的特定简短示例,但它与整个xml文件不匹配。我会再试一次,然后再打给你。顺便说一句,非常感谢。当然,如果您具体解释了它如何不适用于实际情况——错误消息、选择的错误/额外节点等等——我们可以尝试改进XPath以涵盖它。扩展示例以覆盖相关的额外标记将是理想的。我当前的问题是XML在标记中包含xmlns=”“作为名称空间。如果我删除它,它的工作。我正在试图找出如何使它即使与这个名称空间一起工作。我找到了它。我正在使用KNIME,这是一种数据分析工具,它执行可以做各种事情的节点。在执行XPath节点时,我在前面的注释中编写的名称空间存储在“dns”下。所以我的最后一个XPath表达式是://dns:[text()=“区号”]/../following sibling::dns:td。