我解析XML时出现以下错误
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()));
我两天都在打屁股。 任何人都可以帮我解决问题..
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>
答案 0 :(得分: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>