2012-03-07 118 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