简体   繁体   English

如何解析来自Http Response Android的xml

[英]How to parse the xml from Http Response Android

我有来自Http Response的xml,有没有人能给我一个如何使用android中的sax解析器解析那个http响应的例子?

This example assumes that all data is in the root node 此示例假定所有数据都在根节点中

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();
    }

I've used a very little library (it is two files): minimize-xml-parser. 我使用了一个非常小的库(它是两个文件):minimize-xml-parser。 There is a tutorial on how to use it here: http://www.andengine.org/forums/tutorials/robust-xml-parsing-t4281.html 这里有一个如何使用它的教程: http//www.andengine.org/forums/tutorials/robust-xml-parsing-t4281.html

And the library is here: http://code.google.com/p/minimize-xml-parser/ 图书馆就在这里: http//code.google.com/p/minimize-xml-parser/

用于在Android 链接中解析和使用XML数据和Web服务的简化源代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM