jQuery in Action, 3rd edition
The moose likes XML and Related Technologies and the fly likes Getting level of XML file with SAX Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Getting level of XML file with SAX" Watch "Getting level of XML file with SAX" New topic

Getting level of XML file with SAX

Leslie Chaim
Ranch Hand

Joined: May 22, 2002
Posts: 336
Is there any way I can tell in my Handler at what level I am in the XML file?
Or must I handle this with my own logic

Normal is in the eye of the beholder
Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
You need to track the position yourself. One handy way to do this is to add the element's name into a java.util.Stack in startElement() and pop() the top-most element in endElement(). Then, you'll always have the knowledge of how "deep" you are in the hierarchy.

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
I agree. Here's the link: http://aspose.com/file-tools
subject: Getting level of XML file with SAX
It's not a secret anymore!