-3

I'm using the SAX Parser in android. I had to change the EventHandler like this:

else if(xGrowerNotes){
              profile.setGrowerNotes(profile.getGrowerNotes()+chars);
              //random bug
          }

i have a version of an XML file in 4 languages, UTF-8 encoded. I call the parser with

is.setEncoding("UTF-8");

3 languages work fine, however, the spanish one troubles me. It starts like No apretar las plantas. Regul... and the event is 2 times called. Meaning without the change, it would have cut of the first part and set only "ar las plantas. Regul..." as text. If i add "test 1 2 3" in front of the string, the cut moves, meaning it's like the first 13 charackters are cut. It is only in the spanish Version and all documents are same encoded. Adding "test 1 2 3" to the end of the text extends the 2nd string.

Can anyone clarify this please? Thanks in advance!

user1497119
  • 443
  • 6
  • 19

1 Answers1

0

From the documentation:

The Parser will call this method to report each chunk of character data. SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity so that the Locator provides useful information.

This means you must not assume to get all the character data in one call. All chunks reported in maybe several calls must be appended to get the full data.

Henry
  • 42,982
  • 7
  • 68
  • 84
  • well i know that for example & will split the string into 3 parts, however, the spanish text Looks like plain text to me and i cannot figure out why the parser is Splitting the string after x chars – user1497119 Feb 11 '13 at 12:31
  • That's because the buffer used by the parser happened to end in the middle of the text. The contract allows the parser even to deliver each character separately (which would of course be crazy), you program must handle this correctly. – Henry Feb 11 '13 at 12:37
  • so this means i have to verify all numbers aswell? meaning it could happen that a number 2.345123 gives me back 2 Strings 2.34 and 5123 e.g..? – user1497119 Feb 11 '13 at 12:42
  • Yes. This applies to all character data. – Henry Feb 11 '13 at 12:50