如何从Http响应解析XML Android
答
此示例假设所有的数据都是在根节点
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder builder = builderFactory.newDocumentBuilder();
try {
URL url;
url = new URL("http://yourURLhere.com");
Document document = builder.parse(new InputSource(url.openStream()));
Element rootElement = document.getDocumentElement();
try{
//get the different xml fields here
Date xmlDateLastNotification = new Date(rootElement.getAttribute("dateLastNotification").toString());
String someOtherVariable = rootElement.getAttribute("xmlNode").toString();
}catch(Exception e){}
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
答
我已经使用了一个很小的库(它是两个文件):minimize-xml-parser。有关于如何在这里使用它的教程: http://www.andengine.org/forums/tutorials/robust-xml-parsing-t4281.html
您能解析响应吗?请让我们知道,如果你得到它。 – davehale23 2012-03-19 19:45:01