XMLPullFeedParserを使用してxmlを解析しようとしていますが、ICSを除くすべてのデバイスが正常に機能しています。
このような私のxml形式、
<?xml version="1.0" encoding="utf-8"?>
<Result>
<Tag>
<Name>
Bangalore
</Name>
</Tag>
<Tag>
<Name>
Chennai
</Name>
</Tag>
</Result>
Logcatエラー、
08-31 10:36:31.988: ERROR/Error Mian PullFeedParser(12056): Invalid stream or encoding: java.io.IOException: Attempted read on closed stream. (position:START_DOCUMENT null@1:1) caused by: java.io.IOException: Attempted read on closed stream.
08-31 10:36:31.988: ERROR/Error Mian PullFeedParser(12056): org.xmlpull.v1.XmlPullParserException: Invalid stream or encoding: java.io.IOException: Attempted read on closed stream. (position:START_DOCUMENT null@1:1) caused by: java.io.IOException: Attempted read on closed stream.
08-31 10:36:31.988: ERROR/Error Mian PullFeedParser(12056): at org.kxml2.io.KXmlParser.setInput(KXmlParser.java:1730)
私のパーサー:
public List parser(InputStream responseStream){
// TODO Auto-generated method stub
List<Message> messages = null;
XmlPullParser parser = Xml.newPullParser();
try {
parser.setInput(responseStream, null);
int eventType = parser.getEventType();
Message currentMessage = null;
boolean done = false;
while (eventType != XmlPullParser.END_DOCUMENT && !done){
String name = null;
switch (eventType){
case XmlPullParser.START_DOCUMENT:
messages = new ArrayList<Message>();
break;
case XmlPullParser.START_TAG:
name = parser.getName();
if (name.equalsIgnoreCase("Name")){
currentMessage = new Message();
currentMessage.setName(parser.nextText());
}
break;
case XmlPullParser.END_TAG:
name = parser.getName();
if (name.equalsIgnoreCase("Name")&& currentMessage != null){
messages.add(currentMessage);
}
else if(name.equalsIgnoreCase("Result")){
done = true;
}
break;
}
eventType = parser.next();
}
} catch (Exception e) {
Log.e("Error Mian PullFeedParser", e.getMessage(), e);
}
return messages;
}
このXML形式を解析するアイデアを教えてください。
ありがとう。