Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XPath expression for selecting all nodes with a common attribute

Tags:

People also ask

What is the meaning of '/' in XPath?

Single Slash “/” – Single slash is used to create Xpath with absolute path i.e. the xpath would be created to start selection from the document node/start node.

Can we use wildcard in XPath?

XPATH allows the use of wildcards to write more robust path expressions where the use of specific path expressions is either impossible or undesirable. matches any element node. matches any attribute node. matches any type of node.


a book I'm reading on XML says that to select all nodes in an XML file that have a specific attribute, use the syntax:

//*/@_attribute_

What I don't understand is why the asterisk is needed. As I understand it, the expression // selects all descendants of the root node. So, wouldn't //@lang, for example, select all descendants of the root node that have an attribute called "lang"? I can't even interpret what the asterisk even means in the above expression (I know the asterisk in general means "all"). If someone could break it down for me I'd really appreciate it.

Thanks