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