2012-03-07 121 views

回答

2

此示例假设所有的数据都是在根节点

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

您能解析响应吗?请让我们知道,如果你得到它。 – davehale23 2012-03-19 19:45:01

0

简化源代码解析和使用Android中的XML数据和Web服务 link