A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
XML and Related Technologies
Finding maximum node depth of an xml dom tree
Joined: Mar 26, 2012
Apr 23, 2012 04:13:51
How do I find the maximum node depth of an xml file using dom in
Joined: Sep 21, 2011
Apr 23, 2012 05:07:47
Does it need to be DOM? I'm almost (but not quite) certain that you could write a one-line XPath expression to determine that value.
Author and all-around good cowpoke
Joined: Mar 22, 2000
Apr 23, 2012 08:14:52
Obviously you are going to have to traverse the entire document.
With DOM you would use the methods in org.w3c.dom.Node to work through the whole tree.
It would be a lot easier in SAX or StaX.
Using SAX you could increment a "depth" counter with every startElement and decrement with every endElement, tracking the highest value of course.
Do you need to also remember the deepest Node?
It is sorta covered in the
JavaRanch Style Guide
subject: Finding maximum node depth of an xml dom tree
copy xml string into a dom tree
current-element-node property not recognized
ParserImpl for DOM
Convert XSD to XML
Removing the XML node from a DOM object
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014