这个xpath是什么意思? [英] what does this xpath mean?

查看:54
本文介绍了这个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 表示:

Or, expressed in HTML:

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

无论如何,整个 XPath 没有太大意义.不用说,

是无效的 HTML.

The whole XPath does not make too much sense anyway. It goes without saying that <p><table> is invalid HTML.

这篇关于这个xpath是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆