0

我是 Xpath 的新手。我试图编写一个 xpath 表达式,它返回上表行中的所有有效元素(标记为“必需”)。

使用的 XPath:

.//*[@id='reportListItemID0']/td[not(@width) and child::node()] | .//*[@id='reportListItemID0']/td[not(@width) and not(child::node())]

<tr style="" class="deatilRow" id="reportListItemID0" nowrap="">
    <td width="10px">&nbsp;</td>
    <td>04/04/2013</td><!----------------------------Required-->
    <td width="3px" colspan="10">&nbsp;</td>
    <td>Morkel, Rashid</td><!------------------------Required-->
    <td width="3px" colspan="10">&nbsp;</td>
    <td>100668041</td><!-----------------------------Required-->
    <td width="3px" colspan="10">&nbsp;</td>
    <td></td><!--------------------------------------Required-->
    <td width="3px" colspan="10">&nbsp;</td>
    <td>
        <a href="javascript:makePost(somelink);" class="dynamicLinks">XA0404181004596</a><!--Required-->
    </td>
    <td width="3px" colspan="10">&nbsp;</td>
    <td>$31.00</td><!--------------------------------Required-->
    <td width="3px" colspan="10">&nbsp;</td>
    <td>
        <span class="workedYesNoColor">N</span><!----Required-->
    </td>
    <td width="3px" colspan="10">&nbsp;</td>
</tr>

使用的 X-Path 返回以下列出的元素:

<td>04/04/2013</td>
<td>Morkel, Rashid</td>
<td>100668041</td>
<td></td>
<td> <a href="javascript:..." class="dynamicLinks">XA0404181004596</a> </td>
<td>$31.00</td>
<td> <span class="workedYesNoColor">N</span> </td>

但预期结果如下:(只需要叶子节点而不是'td')

<td>04/04/2013</td>
<td>Morkel, Rashid</td>
<td>100668041</td>
<td></td>
<a href="javascript:..." class="dynamicLinks">XA0404181004596</a>
<td>$31.00</td>
<span class="workedYesNoColor">N</span>

重要提示:带有标签“a”和“span”的“td”的位置可能会有所不同。他们并非始终出现在第 5 位和第 6 位。

请让我知道我错过了什么。

4

0 回答 0