I’m parsing some XML with a ContentHandler, and I can get attributes within tags fine, but I don’t see how to get the actual values. For example, take this simple xml:
<code>
< thing id="12345" key="abcde" >
< description > Some text is here < /description >
< otherdata > I don't actually care about or want this text < /otherdata >
< /thing >
</code>
(Apologies for the formatting there…)
So, in my StartElement() I can get the id and key values fine with att.getValue(“id”) for example. But how do I get the text between the description tags?
Based on reading the docs it look like I need to use the characters() method, but this will presumably occur for all other tags in the xml (the real example is more complex than the above, and I don’t need all of it) – how do I relate the character array back to a specific tag? All it gives me is a start and a length but from that I don’t know which element it relates to.
I’m obviously missing something obvious here but none of the docs or examples I find seem to help – most examples just show the whole doc being squirted out to a console, which is fine but doesn’t help with my scenario.
You can put Flag value whenever you parse description inside the
startElement(), and make it false inside theendElement(). In between this, you can have value of description inside thecharacters()method.