A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Java 8 in Action
this week in the
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
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
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
ParserImpl for DOM
copy xml string into a dom tree
current-element-node property not recognized
Removing the XML node from a DOM object
Convert XSD to XML
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014