我正在解析來自此的數據XML url文本輸入因用戶而異。每當文本變量中有空格時,我會得到以下例外:Android中的Saxparser異常
org.apache.harmony.xml.ExpatParser$ParseException: At line 11, column 2: mismatched tag
org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:520)
org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:479)
org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:318)
org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:275)
gps.app.tkartor.XMLObjects.XMLParser.findStreet(XMLParser.java:99)
如果沒有空格,它可以正常工作。解析代碼:
public void findStreet(String searchWord) {
try {
url = new URL(
"http://maps.travelsouthyorkshire.com/iGNMSearchService.asmx/TextSearch?text="
+ searchWord + "&maxResults=100");
System.out.println(url.toString());
parserFactory = SAXParserFactory.newInstance();
parser = parserFactory.newSAXParser();
reader = parser.getXMLReader();
streetHandler = new StreetHandler();
reader.setContentHandler(streetHandler);
reader.parse(new InputSource(url.openStream()));//line 99
poi = streetHandler.getAllStreets();
} catch (Exception e) {
e.printStackTrace();
}
}
這工作,謝謝。 – user1163392 2012-03-25 10:11:46