我一直在尝试解析一个看起来像这样的 xml。这种正确的xml格式是如何解析它的。我想知道xml的格式是什么。
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">1|3|195,317,65,108|342,227,66,99|280,98,84,112</string>
我的 xml 解析器活动是
public class RetrieveFeed extends AsyncTask {
URL url;
ArrayList<String> headlines = new ArrayList();
ArrayList<String> links = new ArrayList();
@Override
protected Object doInBackground(Object[] objects) {
// Initializing instance variables
try {
url = new URL("http://54.179.134.139/viViewapi/api/values");
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(false);
XmlPullParser xpp = factory.newPullParser();
// We will get the XML from an input stream
xpp.setInput(getInputStream(url), "UTF_8");
boolean insideItem = false;
// Returns the type of current event: START_TAG, END_TAG, etc..
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG) {
if (xpp.getName().equalsIgnoreCase("html")) {
insideItem = true;
} else if (xpp.getName().equalsIgnoreCase("pre")) {
if (insideItem)
headlines.add(xpp.nextText()); //extract the headline
}
/*else if (xpp.getName().equalsIgnoreCase("link")) {
if (insideItem)
links.add(xpp.nextText()); //extract the link of article
}*/
} else if (eventType == XmlPullParser.END_TAG && xpp.getName().equalsIgnoreCase("html")) {
insideItem = false;
}
eventType = xpp.next(); //move to next element
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return headlines;
}
public InputStream getInputStream(URL url) {
try {
return url.openConnection().getInputStream();
} catch (IOException e) {
return null;
}
}
public ArrayList<String> heads()
{
return headlines;
}
}
我不知道这种方法是对还是错