Reputation: 1
I extended org.xml.sax.helpers.DefaultHandler
. When during the parsing an element closes and my endElement
callback executes, I would like to be able to tell whether in the XML the element is closed with a whole closing tag like </tag>
, or instead it's an element that opens and closes in the same tag like <tag ... />
.
Is there a good way to distinguish between the two cases?
The reason why I would like this is that after the parsing I need to recreate the XML (with some modifications) from the read elements, and I would like that in the resulting XML the elements that have no characters
in their body close in the same way as they did in the original XML.
I tried by checking that no characters
were received for the current element, as an indication that the element closed on the opening tag itself, with ... />
, but that also happens when there is a closing tag without characters in the body (<tag ...></tag>
).
EDIT: I cannot agree that this is a duplicate of "Is there a semantic difference between and in XML?". That question and its answer only point out that there is no difference between the two ways of closing an element. My question is whether there is a way in SAX to distinguish the two cases.
Upvotes: 0
Views: 72