2012-02-14 81 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