I am extending org.xml.sax.helpers.DefaultHandler to parse a XML.
How can you determine the depth level during parsing?
for example:
<?xml version="1.0" encoding="utf-8"?>
<jsk:Dataset gml:id="Dataset1" ....>
<gml:description>....</gml:description>
<gml:boundedBy>
...
</gml:boundedBy>
</jsk:Dataset>
<jsk:Dataset> tag is on level 0
<gml:description> and <gml:boundedBy> tags are on level 1 and so on…
any guidance on the right direction is appreciated.
The DefaultHandler class indicates that it is processing a new element via the
startElementmethod, and that it has finished processing the same using theendElementmethod. You can hook onto these methods by overriding them in your child class.The approach stated in the other answer of using an instance field to store state can be used in this case as well. Increment on entering
startElementand decrement on exitingendElement.