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
? I'm almost (but not quite) certain that you could write a one-line
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.
you would use the methods in
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?
Java Resources at
I agree. Here's the link:
subject: Finding maximum node depth of an xml dom tree
copy xml string into a dom tree
current-element-node property not recognized
Convert XSD to XML
Removing the XML node from a DOM object
ParserImpl for DOM
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2013