开发者

Data/XML being trucated when displayed

开发者 https://www.devze.com 2023-01-20 13:22 出处:网络
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 parti

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;
        q开发者_如何学PythonuiztitleSet.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);
        }
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号