My project downloads lots of xml (as text) and images then I parse the xml and interpret the data there. When I check some of the xml downloaded some of them are getting truncated only showing a partial part of it. The beginning parts of it is gone. I use:
InputStream in;
in = OpenHttpConnection(url);
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
xr.setContentHandler(this);
xr.parse(new InputSource(in));
Edited:
@Override public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { if (localName.equals("quiz") ) { parsedQuizTitle = new QuizTitle(); in_quiztitle = true; } }
@Override
public void endElement(String namespaceURI, String localName, String qName)
throws SAXException {
if (localName.equals("category") || localName.equals("quiz") ) {
in_quiztitle = false;
quiztitleSet.add(parsedQuizTitle);
}
}
@Override
public void characters(char ch[], int start, int length) {
if (in_quiztitle) {
String quiz_item = new String(ch, start, length);
String[] quiz_item_parsed = null;
String expression = "\\|\\|";
quiz_item_parsed = quiz_item.split(expression);
if(quiz_item_parsed.length == 2) {
parsedQuizTitle.setQuizTitleName(quiz_item_parsed[1]);
parsedQuizTitle.setQuizTitleID(quiz_item_parsed[0]);
}
else {
//add to title
parsedQuizTitle.addtoQuizTitleName(quiz_item);
}
}
}