Finding the deepest node in some XML using XPath
August 22nd, 2006
Today’s problem was, given a set of XML nodes or arbitrary depth, how do I find the deepest node quickly. I have an XML description of a hierarchy of folders in a document respository. It consists of a series of Location elements, each with one or more children.
After quite a bit of pootling around using XPath, I came up with this…
XmlNodeList deepestNodes = _routingInfo.SelectNodes(”//Location[count(child::*)=0]“);
That is (I think) an instruction to select all nodes called Location that have zero children. Now all I need is to find which of these is the deepest.
Also, thanks to http://www.dpawson.co.uk/xsl/sect2/sect21.html which pointed me in the right direction.
Posted in Development |
Comments
Leave a Reply
You must be logged in to post a comment.