public static void parseit(String thexml){
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser;
try {
saxParser = factory.newSAXParser();
DefaultHandler handler = new DefaultHandler() {
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
}
public void endElement(String uri, String localName, String qName)throws SAXException {
}
public void characters(char ch[], int start, int length) throws SAXException {
}
};
saxParser.parse(thexml, handler);
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
Log.e("e", "e", e);
e.printStackTrace();
}catch (ParserConfigurationException e) {
e.printStackTrace();
}
}
這是我的代碼。 (非常感謝這些人:Can someone help me with this JAVA SAXParser?)爲什麼我無法在SAXParser中打開這個XML?
問題是,我總是進入IOException e。消息是這樣的:
java.io.IOException: Couldn't open....and then my XML file.
我的XML文件是這樣的,這是一個字符串:
<?xml version="1.0" encoding="UTF-8"?>
<result>
<person>
<first_name>Mike</first_name>
</person>
</result>
爲什麼不能看我的XML字符串?