在我的應用程序中,我有一些要解析的50到100個數據...還有一些2 MB大小以內的圖像...所有這些都將被檢索到單個活動並進行排序和顯示那裏...Android SAX解析檢索速度很慢
但它需要約2分鐘......那太多了。
如何縮短解析時間?
還是我錯了使用SAX解析???建議請....
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
/** Send URL to parse XML Tags */
URL sourceUrl = new URL(url);
/** Create handler to handle XML Tags (extends DefaultHandler) */
XmlHandler xmlHandler4Profile = new XmlHandler();
xr.setContentHandler(xmlHandler4Profile);
xr.parse(new InputSource(sourceUrl.openStream()));
}
代碼XmlHandler.java
public class XmlHandler extends DefaultHandler{
static GetXml getxml;
Boolean currentElement = false;
String currentValue = null;
@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
// TODO Auto-generated method stub
currentElement=true;
if (localName.equals("root"))
{
/** Start */
getxml = new GetXml();
}
}
@Override
public void endElement(String uri, String localName, String qName)
throws SAXException {
// TODO Auto-generated method stub
currentElement=false;
//**************************display page************************
if (localName.equalsIgnoreCase("DisplayId"))
getxml.setDisplayId(currentValue);
if (localName.equalsIgnoreCase("DisplayPage"))
getxml.setDisplayPage(currentValue);
//**************************category details************************
if (localName.equalsIgnoreCase("CategoryId"))
getxml.setCategoryId(currentValue);
if (localName.equalsIgnoreCase("CategoryName"))
getxml.setCategory(currentValue);
//**************************news details************************
if (localName.equalsIgnoreCase("Picture"))
getxml.setPictureName(currentValue);
if (localName.equalsIgnoreCase("newsHeading"))
getxml.setNewsHeading(currentValue);
if (localName.equalsIgnoreCase("Mainnews"))
getxml.setMainNews(currentValue);
}
@Override
public void characters(char[] ch, int start, int length)
throws SAXException {
// TODO Auto-generated method stub
if (currentElement) {
currentValue = new String(ch, start, length);
currentElement = false;
}
}
是'XmlHandler'類,你能告訴我們它的代碼? – 2012-04-09 12:16:33
@DonRoby檢查代碼 – subrussn90 2012-04-09 12:22:50