2012-02-14 79 views
0

這是我的XML格式,得到了從Web服務XML解析在android中的錯誤?

<?xml version="1.0" encoding="utf-8"?> 



<HaendlerLeistungen> 
    <leistung id="20" name="Autowerkstätte" /> 
    <leistung id="42" name="Barankauf" /> 
    <leistung id="14" name="B-Schein Schulungen" /> 
    <leistung id="41" name="Chrom" /> 
    <leistung id="24" name="Ersatzteile" /> 
    <leistung id="13" name="Fahrschule" /> 
    <leistung id="44" name="Fahrwerk" /> 
    <leistung id="23" name="Finanzierung" /> 

    </HaendlerLeistungen> 

我用下面的代碼編寫文檔對象響應,`

private Document getDomElement(String xml){ 
.... 
... 
      InputSource is = new InputSource(); 
      is.setCharacterStream(new StringReader(xml)); 
      doc = db.parse(is); 

    ... 
    ..... 
      return doc; 
    } 
public Document convertStreamToString() throws IOException { 
    .... 
    .... 
    try { 

    url = new URL("Service URL to fetch corresponding reponse"); 

    urlConn = url.openConnection(); 

    } catch (IOException ioe) { 



    } 
    InputStream is = urlConn.getInputStream(); 
    if (is != null) { 
     StringBuilder sb = new StringBuilder(); 
     String line; 

     try { 
      BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); 
      while ((line = reader.readLine()) != null) { 
       sb.append(line).append("\n"); 
      } 
     } finally { 
      is.close(); 
     } 
     System.out.println("Tight Weight"+sb.toString()); 
     return getDomElement(sb.toString()); 
    } else {   
     return getDomElement(""); 
    } 
}` 

字符串日誌打印整個XML正確的,但是當我嘗試準備Document對象,它拋出以下錯誤

02-14 19:35:46.360: E/Error:(14863): PI must not start with xml (position:unknown [email protected]:5 in [email protected]) 

我不`噸知道我的XML或分析是否問題。如果有人知道解決方案,請幫助我。

注意:響應包含德文字符;

謝謝。

回答

1

是否確定在XML前導碼(<?xml ...?>)之前沒有奇怪的字符(例如BOM)或空格?

什麼是Content-Type標題?你可以向我們發送XML的URL嗎?

嘗試刪除整個序言...

+0

白色空間是我的問題。 – Sababado 2012-07-06 01:55:51