这是我的要求,
我从服务器作为一个肥皂对象得到响应,我将它转换为字符串格式,现在我想提取 xml 数据,
如何提取嵌套标签?
我可以提取所有数据还是需要解析该 XML 响应?有没有办法提取 XML 嵌套标签并将其解析为 ArrayList<> post 是一个类?
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<maintag>
<item>
<name>AndroidPeople</name>
<website category="android">www.androidpeople.com</website>
</item>
<item>
<name>iPhoneAppDeveloper</name>
<website category="iPhone">www.iphone-app-developer.com</website>
</item>
</maintag>
..
如果可能怎么办?
提前致谢。
我看到这是可以使用它以及如何
private static Show getShowFromRSS(Context context, Document feed,
String feedUrl) {
try {
// There should be one channel in the feed, get it.
// Also, the cast should be okay if the XML is formatted correctly
NodeList item = feed.getElementsByTagName("channel");
Element el = (Element)item.item(0);
String title;
NodeList titleNode = el.getElementsByTagName("title");
if (titleNode == null || titleNode.getLength() < 1)
title = context.getString(R.string.default_title);
else
title = titleNode.item(0).getFirstChild().getNodeValue();
String author;
NodeList authorNode = el.getElementsByTagName("author");
if (authorNode == null || authorNode.getLength() < 1)
author = context.getString(R.string.default_author);
else
author = authorNode.item(0).getFirstChild().getNodeValue();
String desc;
NodeList descNode = el.getElementsByTagName("comments");
if (descNode == null || descNode.getLength() < 1)
desc = context.getString(R.string.default_comments);
else
desc = descNode.item(0).getFirstChild().getNodeValue();
String imageUrl;
NodeList imagNode = el.getElementsByTagName("image");
if(imagNode != null) {
Element ima = (Element)imagNode.item(0);
if (ima != null) {
NodeList urlNode = ima.getElementsByTagName("url");
if(urlNode == null || urlNode.getLength() < 1)
imageUrl = null;
else
imageUrl =
urlNode.item(0).getFirstChild().getNodeValue();
} else
imageUrl = null;
} else
imageUrl = null;
return new Show(title, author, feedUrl, desc, imageUrl, -1, -1);
} catch (Exception e) {
// Any parse errors and we'll log and fail
Log.e("NCRSS", "Error parsing RSS", e);
return null;
}
}