我正在使用此代码用 Java 解析 xml 文件,但它不适用于 android SDK
try {
URL url = new URL("http://example.com/file.xml");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(url.openStream());
NodeList nodeList = doc.getElementsByTagName("item");
for (int i = 1; i < nodeList.getLength(); i++) {
Element element = (Element)nodeList.item(i);
System.out.println(element.getFirstChild().getNodeValue());
}
} catch (ParserConfigurationException parserConfigurationException) {
} catch (SAXException sAXException) {
} catch (IOException iOException) {
}
当我尝试将值放入字符串时value always = null
!怎么了 ???
PS:该应用程序具有互联网权限