views:

136

answers:

1

Hi,

I'm using a SAX parser (on android) to parse an xml file from an WebService. On some elements the CDATA is truncated and not complete, e.g. the XML-file contains data like

 <name><![CDATA[Gölsder und Ginck GmbH]]></name> 

and after parsing the xml file with

public void characters(char[] ch, int start, int length)
   throws SAXException {
   super.characters(ch, start, length);
   String text = new String(ch, start, length);

the text only contains "Gölsder und Gin" (the first 15 characters). I debugged it with eclipse and i see that the whole string is not contained in the "char[] ch" argument of the method. so the parsing itself seems to have an error

+2  A: 

I've had this problem, too. The thing is that the characters() method can be called multiple times on the same element. In your case, if you were to write this:

public void characters(char[] ch, int start, int length)
   throws SAXException {
   super.characters(ch, start, length);
   String text = new String(ch, start, length);
   Log.d("XMLTEST", text);
}

You would probably get two log messages, one Gölsder und Gin and one ck GmbH.

In conclusion, you need to have member variables that you concatenate when receiving new characters.

Felix