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>
).
Loris is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1