所以,我正在尝试解析这个XML文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ButtonDescs</key>
<array>
<string>See more information</string>
<string>Talk to a sales person now</string>
<string>Question about this vehicle?</string>
<string>Schedule a Test Drive</string>
<string>Get a quote for this vehicle</string>
<string>Apply for a loan</string>
<string>Calculate monthly payment</string>
<string>Vehicle History Report</string>
</array>
<key>ButtonTitles</key>
<array>
<string>More Details</string>
<string>Call Us</string>
<string>Email Us</string>
<string>Test Drive</string>
<string>Get a Quote</string>
<string>Finance Request</string>
<string>Loan Calculators</string>
<string>CarFax®</string>
</array>
<key>ButtonTypes</key>
<array>
<string>details</string>
<string>phone</string>
<string>vehicle_question</string>
<string>test_drive</string>
<string>quote</string>
<string>credit_form</string>
<string>loan_calculators</string>
<string>carfax</string>
</array>
</dict>
</plist>
这是我正在使用的解析器:
XmlPullParserFactory factory;
try {
factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser xpp = factory.newPullParser();
InputStreamReader inputStreamReader = new InputStreamReader(getUrlData(context, url));
xpp.setInput(inputStreamReader);
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if(eventType == XmlPullParser.START_TAG) {
if(xpp.getName().equalsIgnoreCase("key")) {
xpp.next();
if(xpp.getText().equalsIgnoreCase("ButtonDescs"))
btnMembers = ButtonMembers.DESCS;
else if(xpp.getText().equalsIgnoreCase("ButtonTitles"))
btnMembers = ButtonMembers.TITLES;
else if(xpp.getText().equalsIgnoreCase("ButtonTypes"))
btnMembers = ButtonMembers.TYPES;
} else if(xpp.getName().equalsIgnoreCase("array")) {
i = 0;
} else if(xpp.getName().equalsIgnoreCase("string")) {
if(btnMembers == ButtonMembers.DESCS) {
button = new InventoryDetailButton();
xpp.next();
button.setDescription(xpp.getText());
btnList.add(button);
} else if(btnMembers == ButtonMembers.TITLES) {
xpp.next();
btnList.get(i).setTitle(xpp.getText());
} else if(btnMembers == ButtonMembers.TYPES) {
xpp.next();
btnList.get(i).setType(xpp.getText());
}
}
} else if(eventType == XmlPullParser.END_TAG) {
if(xpp.getName().equalsIgnoreCase("string")) {
i++;
} else if(xpp.getName().equalsIgnoreCase("array") && btnMembers == ButtonMembers.TYPES) {
return btnList;
}
}
eventType = xpp.next();
}
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
我可以将URL直接复制并粘贴到浏览器中,我将获得上面粘贴的XML。但是,当解析器开始浏览标记时,它不是预期的标记。我可以单步执行此过程,xpp
对象的名称将为html
,meta
和script
。一旦到达script
标记,解析器就会崩溃。
有没有人知道这些标签可能来自哪里?
答案 0 :(得分:2)
有没有人知道这些标签可能来自哪里?
来自您的Web服务器,它无法识别您的请求并返回网页,可能带有某种形式的错误信息。