2011-04-01 169 views
0

我收到以下錯誤,當我分析我的XMLAndroid中的SAX解析器?

org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 0: no element found 
04-01 22:23:13.661: WARN/System.err(628):  at org.apache.harmony.xml.ExpatParser.finish(ExpatParser.java:553) 
04-01 22:23:13.661: WARN/System.err(628):  at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:483) 
04-01 22:23:13.672: WARN/System.err(628):  at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:320) 
04-01 22:23:13.672: WARN/System.err(628):  at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:277) 

這是我的代碼

url= new URL(queryString);   
SAXParserFactory spf = SAXParserFactory.newInstance(); 
SAXParser sp = spf.newSAXParser(); 
XMLReader xr = sp.getXMLReader(); 
PersonHandler myExampleHandler = new PersonHandler(); 
xr.setContentHandler(myExampleHandler); 
xr.parse(new InputSource(url.openStream())); 

我struking兩天。 任何一個可以幫助我解決我的問題..

XML結構

<xml> 
    <item> 
    <queryType>compare-celebrity</queryType> 
    <memberID>43</memberID> 
    <memberName>Sachin</memberName> 
    <memberSurname>Ramesh</memberSurname> 
    <memberPersonalityType>[Red-Blue] Double</memberPersonalityType> 
    <celebrityID>118</celebrityID> 
    <celebrityName>Brad Pitt</celebrityName> 
    <thumbnail>brad-pitt-1299831254.jpeg</thumbnail> 
    </item> 
</xml> 

回答

2

似乎xml is not a valid element name。以字符串「xml」開始

名稱,或與將匹配(('X'|'x') ('M'|'m') ('L'|'l'))任何字符串,保留對該或未來版本本規範的標準化。

根元素使用不同的名稱:

<items> 
    <item> 
    <queryType>compare-celebrity</queryType> 
    <memberID>43</memberID> 
    <memberName>Sachin</memberName> 
    <memberSurname>Ramesh</memberSurname> 
    <memberPersonalityType>[Red-Blue] Double</memberPersonalityType> 
    <celebrityID>118</celebrityID> 
    <celebrityName>Brad Pitt</celebrityName> 
    <thumbnail>brad-pitt-1299831254.jpeg</thumbnail> 
    </item> 
</items> 
+0

喜對不起,那朵是我的XML結構,TAT時間我被編輯的職位。 – David 2011-04-01 17:41:09

+0

謝謝..更改根元素後。其工作正常 – David 2011-04-05 13:20:50

+0

更改根元素後仍然收到解析器異常。並非所有的時間。 – David 2011-04-06 14:03:04