Xml xpath是否可以搜索子节点并返回其他节点?
我能够将“首字母缩略词”子节点从以下节点中分离出来Xml xpath是否可以搜索子节点并返回其他节点?,xml,xpath,Xml,Xpath,我能够将“首字母缩略词”子节点从以下节点中分离出来 <tr id="PRO_0000155160"> <td> <input type="checkbox" class="cart-item" onclick="addOrAppendCart('P19614_1-66_', 'section_features')" id="checkbox_P19614_1-66_" /> </td> <td style="white-s
<tr id="PRO_0000155160">
<td>
<input type="checkbox" class="cart-item" onclick="addOrAppendCart('P19614_1-66_', 'section_features')" id="checkbox_P19614_1-66_" />
</td>
<td style="white-space:nowrap;">
<acronym title="Extent of a polypeptide chain in the mature protein." onclick="dialog('chain'); Event.stop(event || window.event); return false" onmousedown="Event.stop(event || window.event);">Chain</acronym>
</td>
<td class="numeric">
<a href="/blast/?about=P19614[1-66]">1 – 66</a>
</td>
<td class="numeric">66</td>
<td>Type-3 ice-structuring protein HPLC 12</td>
<td style="text-align:center" class="ft-sequence">
<table class="sequence" style="cursor:pointer" onclick="window.location.href='../blast/?about=P19614[1-66]'" title="Length: 66">
<tr>
<td style="width:100%;" class="feature chain"> </td>
</tr>
</table>
</td>
<td>
<span style="font-size: small;">PRO_0000155160</span>
</td>
</tr>
但是,我想返回它上面的“输入”节点(第3行)或它下面的“href”节点(第9行)
通常,我会编写一个xpath查询,直接提取输入或href节点,但是首字母缩写词节点必须满足我的问题的特定条件,即在onclick属性中包含单词“chain”
这样做可以确保我拥有正确的“tr”根节点(主xml文件中有多个tr),但是正如我所提到的,我需要该特定tr根节点的输入或href节点
这可能吗?我已尝试将../附加到查询的末尾,但这不起作用。“上面”会误导您。“之前”会让你更靠近
详细说明你想做什么。从所选的首字母缩略词
,您需要最接近的前面的
元素,因此将/previous::input[1]
添加到路径的末尾。(需要[1]
,否则将匹配文档前面的所有
元素
类似地,使用以下命令::
轴查看文档中的后续内容,无结构约束
(或者,您可以更明确地知道所需节点相对于您找到的节点的确切位置,如果文档结构并非始终如图所示那么简单,那么这将更加健壮,并且可以提高性能。但这是您需要在准确了解输入文档中的预期内容的基础上进行设计的。)关于//input[//tr[contains(@id,'.''')]//首字母缩写词[contains(@onclick,'chain')]]
//tr[contains(@id, '_')]//acronym[contains(@onclick,'chain')]