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或分析是否問題。如果有人知道解決方案,請幫助我。
注意:響應包含德文字符;
謝謝。
白色空間是我的問題。 – Sababado 2012-07-06 01:55:51