Wednesday, 21 September 2011

XML: Find out node which doesn’t have a given attribute

Question: Find out a node which doesn't have a given attribute.
For e.g., in the given xml, get the third Child node which doesn’t have the attribute ‘name’.

<?xml version="1.0" encoding="UTF-8"?>
<Children>
	<Child name='A' />
	<Child name='B' />
	<Child />
	<Child age='30'/>
</Children>


XPath to find nodes without ‘name’ attribute
/Children/Child[not(@name)]


XPath to find nodes without ‘name’ and ‘age’ attribute
/Children/Child[not (@name) and not(@age)]

No comments:

Post a Comment

Note: only a member of this blog may post a comment.