开发者

How to solve SAXParseExecption in android?

开发者 https://www.devze.com 2023-01-26 02:31 出处:网络
I am developing an application,In my application,I am displaying lot of images from url using DOM xml parsing,It is working fine,but some time i got org.xml.sax.SAXParseException: Unexpected end of th

I am developing an application,In my application,I am displaying lot of images from url using DOM xml parsing,It is working fine,but some time i got org.xml.sax.SAXParseException: Unexpected end of the documentin my xml parsing handler.How to solve this problem,please help me.This is my xml parsing handler code

public String parse_bannerlink() throws UnknownHostException{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
String开发者_开发百科 bannerlink=null;
try {
DocumentBuilder builder = factory.newDocumentBuilder();
Document dom = builder.parse(this.getInputStream());
org.w3c.dom.Element root = dom.getDocumentElement();
NodeList items = root.getElementsByTagName("partypicbanner");
for (int i = 0; i < items.getLength(); i++) {
Node item = items.item(i);
NodeList properties = item.getChildNodes();
for (int j = 0; j < properties.getLength(); j++) {
Node property = properties.item(j);
String name = property.getNodeName();
if (name.equalsIgnoreCase("link")) {
bannerlink=property.getFirstChild().getNodeValue();
}
}}
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
return bannerlink;
}

Thanks all


Try to validate your input file with any xml-validator, for example this: Xml validator


You are definitely not parsing that document using DOM you are parsing it using SAX. I'd check the document you are trying to parse as apparently that document is not valid.

UPDATE: Apparently I was wrong. Didn't know that DOM throws that exception too.

0

精彩评论

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