xpath - 这个xpath是什么意思?

标签 xpath

//p[not(ancestor::*[3])]
  //table[ancestor::*[1][self::p] or ancestor::*[2][self::p]]
    tr/td//a[ancestor::*[1`][self::td] or ancestor::*[2][self::td]]

最佳答案

//                               # from the root node, look at all descendants
p[                               # select nodes of type <p>, who have…
  not(ancestor::*[3])            #   …no ancestor 3 levels up
]                                #
//                               # from these nodes, select descendants
table[                           # of type <table>, who have…
  ancestor::*[1][self::p]        #   …a <p> as their direct ancestor
  or                             #   or
  ancestor::*[2][self::p]        #   …a <p> as their second ancestor
]                                # 
                                 # syntax error, this should be a location step
tr                               # …select all nodes of type <tr>
/                                # from their children…
td                               # …select all nodes of type <td>
//                               # from their descendants…
a[                               # …select all nodes of type <a>, who have
  ancestor::*[1][self::td]       #   …a <td> as their direct ancestor   
  or                             #   or 
  ancestor::*[2][self::td]       #   …a <td> as their second ancestor
]

或者,用 HTML 表示:

<html>
  <body>
    <p>
      <table>
        <tr> 
          <td>
            <a title="These would be selected." />
          </td>
        </tr>
      </table>
    </p>
  </body>
</html>

无论如何,整个 XPath 没有太大意义。不言而喻<p><table> HTML 无效。

关于xpath - 这个xpath是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4571169/

相关文章:

xpath - 将没有节点本身的xml节点内容提取到jmeter中的变量中

r - R : include an XML element not present in all records

java - 如何将JAVA字符串传递给Input ID

python - 我想将多个段落提取到一个 csv 文件中,但我希望它们在不同的列中而不是在一个大列中

xpath - 如何检查节点是否在表单标签内?

java - 撒克逊不同值抛出异常

xml - 使用xslt转换嵌套的子节点

xml - 如何在 XPath 中通过属性命名空间查找元素

xml - XSLT:检查是否在节点列表中找到节点

python - 维护段落计数