为所有节点获取XPATH [英] get XPATH for all the nodes

查看:106
本文介绍了为所有节点获取XPATH的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何库可以为我的所有HTML页面中的节点提供XPATH?

解决方案


是否有任何库可以给我
XPATH用于HTML页面中的所有节点

是的,如果这个HTML页面是格式良好的XML文档



取决于您对节点的理解...

  // * 

选择所有文档中的元素。

  / descendant-or-self :: node()

选择所有元素,文本节点,处理指令,注释节点和根节点 /

  // text()

选择文档中的所有文本节点。

  // comment()

选择文档中的所有注释节点。

  //处理指令()

选择文档中的所有处理指令。

  // @ * 

选择文档中的所有属性节点。

  //命名空间:: * 

选择文档中的所有名称空间节点。

最后,可以使用union( |

因此,我认为下面的表达式确实选择了任何XML文档的所有节点:

  / descendant-or-self :: node()| // @ * | // namespace :: * 


is there any library that can give me XPATH for all the nodes in HTML page ?

解决方案

is there any library that can give me XPATH for all the nodes in HTML page

Yes, if this HTML page is a well-formed XML document.

Depending on what you understand by "node"...

//*

selects all the elements in the document.

/descendant-or-self::node()

selects all elements, text nodes, processing instructions, comment nodes, and the root node /.

//text()

selects all text nodes in the document.

//comment()

selects all comment nodes in the document.

//processing-instruction()

selects all processing instructions in the document.

//@* 

selects all attribute nodes in the document.

//namespace::*

selects all namespace nodes in the document.

Finally, you can combine any of the above expressions using the union (|) operator.

Thus, I believe that the following expression really selects "all the nodes" of any XML document:

/descendant-or-self::node() | //@* | //namespace::*

这篇关于为所有节点获取XPATH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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