这里是我的要求,如何从Soap对象中提取XML嵌套标记?
我正在从服务器作为SOAP对象的反应,我把它转换成字符串格式,现在我想提取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;
}
}
您需要一个XML解析器。 通过这篇文章看看:http://stackoverflow.com/questions/373833/best-xml-parser-for-java – 2013-04-05 06:03:36
我更新我的问题 – yakusha 2013-04-05 06:13:41