I want to parse some data from an xml file using SAX parser. My xml is as follows:
<categories>
<cat>Pies & past</cat>
<cat>Fruits</cat>
</categories>
In order to parse this data I extend DefaultHandler.
The output after parsing is:
cat 1 = Pies
cat 2 = &
cat 3 = past
cat 4 = Fruits
Why is this happening instead of getting:
cat 1 = Pies & past
cat 2 = Fruits
My guess is that you are treating each call to
charactersas delivering the complete text for acatelement. You should code your handler so that successive calls tocharactersaccumulate the text, and you only capture it on theendElementevent: