所以,我试图通过这个 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
有谁知道这些标签可能来自哪里?