How to select xpath script in html head?

How to select xpath script in html head?

Example (how to select only ThisFile1.js?):

<html> <head> <script type="text/javascript" src="ThisFile1.js"></script> </head> <body> <script type="text/javascript" src="NotThisFile1.js"></script> <script type="text/javascript" src="NotThisFile2.js"></script> <script type="text/javascript" src="NotThisFile3.js"></script> <script type="text/javascript" src="NotThisFile4.js"></script> </body> </html> 

Thank you Yosef

+4
source share
1 answer

Using

 /*/head/script/@src 

or

 string(/*/head/script/@src) 

The first XPath expression selects all src attributes of all script elements that are children of all head elements that are children of the top element in the XML document.

Second XPath expression evaluates the string value of the first attribute selected by the first XPath expression. This would be most convenient if your XPath API provides support for evaluting XPath expressions that nodes do not select. If this is not the case, you should use the first XPath expression and then use the appropriate API method / property that returns the string value of the selected node attribute.

+4
source

Source: https://habr.com/ru/post/1336682/


All Articles