2011-11-21 39 views
0

當我登錄被調用的XML文件的值時,文件每次都在相同的地方結束。它將不完整的數據保存爲一個字符串,然後將其傳遞給我的XMLfromString函數,這些錯誤輸出並顯示異常。 (見下面的錯誤)Android獲取XML不返回整個文件

我想知道是否有什麼我需要改變,以確保頂部閱讀整個文件。

String xml = XMLfunctions.getXML(items); 
    Document doc = XMLfunctions.XMLfromString(xml); 

public static String getXML(String roomID) 
{ 
    Log.d(TAG, roomID + "PASSED"); 

    String line = null; 

    try 
    { 

     DefaultHttpClient httpClient = new DefaultHttpClient(); 
     HttpGet httpPost = new HttpGet("http://mywebsite.com/xml_data/" + roomID + "_meeting_info.xml?id=cacheSTOP3"); 

     HttpResponse httpResponse = httpClient.execute(httpPost); 
     HttpEntity httpEntity = httpResponse.getEntity(); 
     line = EntityUtils.toString(httpEntity); 

    } catch (UnsupportedEncodingException e) { 
     line = "<results status=\"error\"><msg>Can't connect to server</msg></results>"; 
    } catch (MalformedURLException e) { 
     line = "<results status=\"error\"><msg>Can't connect to server</msg></results>"; 
    } catch (IOException e) { 
     line = "<results status=\"error\"><msg>Can't connect to server</msg></results>"; 
    } 
    Log.d(TAG, line); 
    return line; 
} 






public final static Document XMLfromString(String xml){ 

     Document doc = null; 

     DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 
     try { 

      DocumentBuilder db = dbf.newDocumentBuilder(); 

      InputSource is = new InputSource(); 
      is.setCharacterStream(new StringReader(xml)); 
      doc = db.parse(is); 

     } catch (ParserConfigurationException e) { 
      System.out.println("XML parse error: " + e.getMessage()); 
      return null; 
     } catch (SAXException e) { 
      System.out.println("Wrong XML file structure: " + e.getMessage()); 
      return null; 
     } catch (IOException e) { 
      System.out.println("I/O exeption: " + e.getMessage()); 
      return null; 
     } 

     return doc; 

    } 

我得到的錯誤信息是:

11-21 11:11:55.456: INFO/System.out(282): Wrong XML file structure: unterminated entity ref (position:ENTITY_REF &@211:21 in [email protected]) 

任何幫助將非常感激。

+0

上面哪一行產生錯誤? –

+0

@Peter請看我上面的編輯。我遺漏了第二個函數,它在xml不完整時顯示異常。 – Denoteone

+0

代碼沒問題。輸入XML一定有問題。檢查第211行,第21列。將Xml通過驗證器http://www.w3schools.com/xml/xml_validator.asp –

回答

0

檢查你的xml,不管它是否合適,是否有任何關閉或不關閉的標籤。如果可能的話告訴我們哪一行是282,並且發佈你的xml。