Fuzzy interpretation of XmlPullParser.END
I have found twofold treatment of XmlPullParser.END_DOCUMENT
tag in Android's built-in SAX parser. Code is simple:
String s; //actually contains XML
//blah-blah
factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(false);
xpp = factory.newPullParser();
StringReader sw=new StringReader(s);
xpp.setInput(sw);
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT)
{
if (eventType == XmlPullParser.START_TAG)
{
//blah-blah
}
else if(eventType==XmlPullParser.TEXT)
{
//blah-blah
}
else if (eventType == XmlPullParser.END_TAG)
{
//blah-blah
}
eventType=xpp.next();
}
If XML document basically looks like (String s):
<?xml version="1.0" encoding="utf-8"?>
<templates>
<template key="Person" name="Person">
<field key="Photo" name="Photo" type="image" hint="Press to select image"/>
</template>
</templates>
With this everything works fine. But if there are some extra characters after final tag </templates>
- here goes weird side (nature of my XML is such that sometimes there can appear some litter symbols after final tag).
For nearly all Android devices (about 90%) SAX parser ignores extra characters, but in some of devices - mostly devices with ICS - SAX parser tries to parse extra characters and crashes.
So the question is: what says XML standard? Should SAX parser try to parse extra symbols after final tag? And what anyway is XmlPullParser.END_DOCUMENT
- it's either end of data or just final tag?
如果根元素的结束标记后面有非空白字符,则该文件不是格式良好的XML,并且解析器需要向应用程序报告此事实。
链接地址: http://www.djcxy.com/p/5950.html