我正在使用不适用于 ICS 版本的 Android 的 XML 解析从服务器获取一些数据。请告诉我我做了什么更正,以便我也应该在 ICS 上运行......(它在较低的情况下工作正常版本)。这是我的代码
try {
URL url = new URL(
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new InputSource(url.openStream()));
doc.getDocumentElement().normalize();
NodeList nodeList = doc.getElementsByTagName("file");
namephoto = new String[nodeList.getLength()];
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
Element fstElmnt = (Element) node;
NodeList nameList = fstElmnt.getElementsByTagName("file");
Element nameElement = (Element) nameList.item(0);
nameList = nameElement.getChildNodes();
namephoto[i] = ((Node) nameList.item(0)).getNodeValue();
}
} catch (Exception e) {
Log.e("name", "" + e);
}
photobitmap = new Bitmap[namephoto.length];
setPhotoBackground(namephoto[index_photo]);
我的 XML 代码是这样的。
<?xml version="1.0"?>
-<root><file>1 a.JPG</file><file>2 b.JPG</file><file>3 c.JPG</file><file>4 d.JPG</file> </root>