私はこのように見えるXMLを解析しようとしています。 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;
}
}
は、私はアプローチが正しいか間違っているかどうかわからないです
あなたのタイトルには問題がありますが、問題の内容はわかりません。あなたの質問の本文には「XMLの形式は何か知りたい」と書かれていますが、それはSOのための完全に不適切な質問です.XMLの形式を説明する参考資料がたくさんあります。 –