[英]How to parse XML With XmlPullParser?
I read an Xml file with XmlPullParser but it gives Exception (unterminated entity ref (position:TEXT @817:4 in java.io.InputStreamReader@4cb5258) when it comes to Dscp .我用 XmlPullParser 读取了一个 Xml 文件,但是当涉及到Dscp时,它给出了异常(未终止的实体引用(位置:TEXT @817:4 in java.io.InputStreamReader@4cb5258)。
i reader another shot like this before this shot every thing is ok until this one.在这个镜头之前,我读了另一个这样的镜头,直到这个镜头之前一切都好。 when i remove Dsec from xml every thing is ok and i read all xml file.当我从 xml 中删除 Dsec 时,一切正常,我读取了所有 xml 文件。 when i read xml with Dsec i have exception in this shot当我用 Dsec 读取 xml 时,我在这个镜头中有异常
The shot before is like this shot之前的镜头是这样的
<Shot>
<ShotGUID>59AA1C15D3384B5691FBFB40B0FE38BD</ShotGUID>
<Title>##Step 2-Categories of Projects</Title>
<StartTime>00:00:40.00</StartTime>
<EndTime>00:00:00.00</EndTime>
<FileName>Shot0042.jpg</FileName>
<Dscp>Step 2-Categories of Projects
Aggregate project plan identifies four separate categories of projects:
Derivative projects … those that are only incrementally different from existing offerings
Platform projects … major departures from existing offerings … the next generation
Breakthrough projects … involving a newer technology … possibly a “disruptive” technology
R&D projects … “blue sky” or visionary endeavors
</Dscp>
<Footer></Footer>
</Shot>
And this is my code :这是我的代码:
XmlPullParserFactory parserFactory;
parserFactory = XmlPullParserFactory.newInstance();
XmlPullParser parser = parserFactory.newPullParser();
ByteArrayInputStream byteArrayInputStreamXmlData = new ByteArrayInputStream(bufferXMLData);
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
parser.setInput(byteArrayInputStreamXmlData, "UTF-8");
List<PageModel> pages = new ArrayList<>();
int eventType = parser.getEventType();
PageModel current = null;
while (eventType != XmlPullParser.END_DOCUMENT) {
String eltName = null;
switch (eventType) {
case XmlPullParser.START_TAG:
eltName = parser.getName();
if (eltName.equals("Shot")) {
current = new PageModel();
pages.add(current);
} else if (current != null) {
switch (eltName) {
case "ShotGUID":
current.setShotGUID(parser.nextText());
break;
case "StartTime":
current.setStartTime(parser.nextText());
break;
case "EndTime":
current.setEndTime(parser.nextText());
break;
case "FileName":
current.setFileName(parser.nextText());
break;
case "Dscp":
current.setDscp(parser.nextText());
case "Footer" :
current.setFooter(parser.nextText());
break;
}
}
break;
}
eventType = parser.next();
}
After much research I realized that I couldn't use the & character in the Dscp Value and I need to use alternate codes.经过大量研究,我意识到我不能在 Dscp 值中使用&字符,我需要使用替代代码。
What are the special characters in XML? XML 中有哪些特殊字符?
< (<), & (&), > (>), " ("), and ' (').
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.