XPath to return non-empty values

This is an example of an XPath I’ve used before to get the nodes with a non-empty attribute:
// Where rows have a non-empty subtag called field with a name attribute equal to attrib1, select the rows
XmlNodeList nodeList = xmlDocument.SelectNodes("./idc:row[./idc:field[@name='attrib1'][text()]]", xmlnsmgr);

Note: the key part in this XPath is the text() part.

I’m not totally convinced this is the correct XPath to be using.
Of course there is also the node() function.
Combining these with not (e.g. not(node())) may yield the correct way to do it.

For further information try:
W3C XML Path Language (XPath) Spec
MSDN XmlNode.SelectNodes Method


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s