This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting level of XML file with SAX

 
Leslie Chaim
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic