Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get XPATH for all the nodes

Is there a library that can give me the XPATH for all the nodes in an HTML page?

like image 741
user583726 Avatar asked Apr 13 '11 01:04

user583726


People also ask

How get Dom from XPath?

Just pass the element in function getXPathOfElement and you will get the Xpath .

What is text () in XPath?

XPath text() function is a built-in function of the Selenium web driver that locates items based on their text. It aids in the identification of certain text elements as well as the location of those components within a set of text nodes. The elements that need to be found should be in string format.


1 Answers

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::* 
like image 52
Dimitre Novatchev Avatar answered Sep 22 '22 21:09

Dimitre Novatchev