我的项目下载了大量的xml(作为文本)和图像,然后我解析了xml并解释了那里的数据。当我检查一些下载的xml时,其中一些被截断只显示它的一部分。它的开头部分已经消失了。我用:
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));
编辑:
@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);
}
}
}