我已经阅读了大多数似乎相同的错误,但我没有看到它。我的代码假设只使用我要求的项目,但我什么都没得到。我已经注释掉的底部的行将填充myXML,但是我的if代码被忽略了。我使用下面的名称字段,以为我可以将其设置为旗帜,但这并不起作用。我尝试过xpp.getName()。equalsIgnoreCase(" summary"),也没有运气。我的XML来自http://maps.googleapis.com/maps/api/directions/xml?origin=Toronto&destination=Montreal&sensor=false
while (eventType != XmlPullParser.END_DOCUMENT) {
String name = xpp.getName();
if(eventType == XmlPullParser.START_DOCUMENT) {
System.out.println("Start document");
name = xpp.getName();
} else if(eventType == XmlPullParser.START_TAG) {
System.out.println("Start tag " + xpp.getName());
name = xpp.getName();
} else if(eventType == XmlPullParser.END_TAG) {
System.out.println("End tag " + xpp.getName());
} else if (eventType == XmlPullParser.TEXT)
name = xpp.getName();
{
System.out.println("Text " + xpp.getText());
if (name == "summary") { myXML = myXML + xpp.getText() + "\n"; }
if (name == "duration") { myXML = myXML + "Duration:" + " "; }
if (name == "distance") { myXML = myXML + "Distance:" + " "; }
if (name == "value") { myXML = myXML + xpp.getText() + " "; }
if (name == "text") { myXML = myXML + xpp.getText() + "\n"; }
if (name == "html_instructions") { myXML = myXML + xpp.getText() + "\n"; }
if (name == "maneuver") { myXML = myXML + xpp.getText() + "\n"; }
//myXML = myXML + xpp.getText() + "\n";
}
try {
eventType = xpp.next();
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println("End document");
return myXML;
}
答案 0 :(得分:0)
我精心想象的是,我对启动标签的检查需要在if else中作为开始标签。那时我能够继续前进。