Is there any way to get all the childrens node values within the ul tag.
Input:
<ul> <li class="type">Industry</li> <li><a href="/store/Browse/?N=355+361+4294855087">Automotive</a></li> <li><a href="/store/Browse/?N=355+361+4294855065">Parts </a></li> <li>Tires</li> </ul>
Output: Industry, Automotive, Parts, Tires.
For the div element with an id attribute of hero //div[@id='hero'] , these XPath expression will select elements as follows: //div[@id='hero']/* will select all of its children elements. //div[@id='hero']/img will select all of its children img elements. //div[@id='hero']//* will select all of its descendent elements.
As defined in the W3 XPath 1.0 Spec, " child::node() selects all the children of the context node, whatever their node type." This means that any element, text-node, comment-node and processing-instruction node children are selected by this node-test.
Do note that /html/text() doesn't select all text nodes in the document -- only the text nodes that are children (not descendents) of the top, html element. You probably want /html//text() . Some knowledge and understanding of XPath is typically required in order to construct XPath expressions.
This will retrieve all text elements with a parent ul
element.
//ul/descendant::*/text()
You can use XPath axis. An axis represents a relationship to the context node, and is used to locate nodes relative to that node on the tree. As of today there are 13 axes. You can use descendant
for all of the children (including nested) of the context node or descendant-or-self
axis which indicates the context node and all of its descendants. For example:
//ul/descendant::*/text() //ul/descendant-or-self::*/text()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With