0
我想從xml文件中獲取一些信息我嘗試過不同的鏈接,但它工作正常,但是當我通過這個url =「http://www.w3schools.com/xml/simple.xml」它捕獲的SAXException 這是我的代碼使用xml解析
public class XMLfunctions {
public Document getDomElement(String xml){
Document doc = null;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(xml));
doc = db.parse(is);
} catch (ParserConfigurationException e) {
Log.e("Error: ", e.getMessage());
return null;
} catch (SAXException e) {
Log.e("Error: ", e.getMessage());
return null;
} catch (IOException e) {
Log.e("Error: ", e.getMessage());
return null;
}
// return DOM
return doc;
}
它惹人(SAXException的E) 誰能幫助我如何才能避免這個問題?