2012-02-14 26 views
0

は私が正しく `Android解析でXML解析エラーが発生しましたか?

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(""); 
    } 
}` 

、Documentオブジェクトを準備するために、文字列のログを印刷全体のXMLを次のコードを使用しますが、私はしようとすると、Webサービスからの応答として

<?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> 

を得た。これは私のXMLフォーマットでありますそれは誤り

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

次スローDocumentオブジェクトを準備するために私は私のXMLや解析中かどうかの問題を知っている `tを。誰かが解決策を知っている場合は、私を助けてください。

注:応答にはドイツ語の文字が含まれています。

ありがとうございました。

答えて

1

XMLプリアンブル(<?xml ...?>)の前に空白(空白など)や空白がないことを確認してください。

Content-Typeヘッダーとは何ですか? XMLのURLを送ってもらえますか?

プリアンブル全体を削除してください...

+0

空白は私の問題でした。 – Sababado

関連する問題