在我的应用程序中,我有一些要解析的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