Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XPath: select child elements that do *not* have a specific name

Tags:

xpath

<a>    <b/>    <c/>    <d/>    <b/>    <e/> </a> 

How do I select those children of "a" that are not "b"?

like image 886
Thomas Avatar asked Jan 28 '10 16:01

Thomas


People also ask

How do you specify a child element using XPath?

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.

What does * indicate in XPath?

The XPath default axis is child , so your predicate [*/android.widget.TextView[@androidXtext='Microwaves']] is equivalent to [child::*/child::android.widget.TextView[@androidXtext='Microwaves']] This predicate will select nodes with a android. widget. TextView grandchild and the specified attribute.

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.

Which is the child path operator in XPath?

Path (Children): the child operator ('/') selects from immediate children of the left-side collection.


1 Answers

/a/*[not(self::b)]

like image 158
AakashM Avatar answered Oct 15 '22 00:10

AakashM