How to deal with empty tags in a SAX Parser

Hi,

I hope someone can help me with the problem I am having!

Basically, I have written an xml-editor application. When an XML file is selected, I parse the file with a SAX parser and save the start and end locations of all the tags and character data. This enables me to display the xml file with the tags all nicely formatted with pretty colours. Truly it is a Joy To Behold. However, I have a problem with tags in this form:

<package name="boo"/>

because the SAX parser treats them like this:

<package name = boo>

</package>

for various complex reasons the latter is unaccetable so my question is: Is there some fiendishly clever method to detect tags of this type as they occur, so that I can treat them accordingly?

Thanks,

Chris

[814 byte] By [Flat_Doga] at [2007-10-3 4:39:55]
# 1
The fiendishly clever method is to notice that no other methods are called between the startElement() and endElement() methods for that element.
DrClapa at 2007-7-14 22:43:51 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

> The fiendishly clever method is to notice that no

> other methods are called between the startElement()

> and endElement() methods for that element.

Ha! I believe the word commonly used in this situation is "doh". I blame lack of sleep, too much coffee and plain ol' stupidity. Mom would be so proud.

Flat_Doga at 2007-7-14 22:43:51 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

Actually you can potentially differentiate empty elements by using a Locator which you get by implementing setDocumentLocator in your SAX Handler.

This tells you the line number and column of the current event and will be the same for the opening and closing tag of an empty element.

Note: a given SAX parser is not required to set the Locator,

andy_murdocha at 2007-7-14 22:43:51 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...