CDATA XML truncated on parsing

I use the SAX parser (on android) to parse the XML file from the WebService. On some elements, CDATA is truncated and not completed, for example. The XML file contains data such as

 <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 contains only "Gölsder und Gin" (first 15 characters). I debugged it using eclipse, and I see that the whole line is not contained in the argument to the char [] ch "method. Therefore, the syntax analysis itself has an error

+3
source share
2 answers

. , characters() . , :

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);
}

, : Gölsder und Gin ck GmbH.

-, .

+3

felix

private String text;

@Override
public void endElement(java.lang.String uri,
                       java.lang.String localName,
                       java.lang.String qName)
        throws SAXException {
       text = null;
}

@Override
public void characters(char[] ch, int start, int length)
        throws SAXException {
    super.characters(ch, start, length);
    if(text != null){
        text += String.copyValueOf(ch, start, length);
    } else {
        text = String.copyValueOf(ch, start, length);
    }
}
0

Source: https://habr.com/ru/post/1757881/


All Articles