首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > XML SOAP >

打包获取的xml节点

2012-12-28 
封装获取的xml节点SAXReader reader new SAXReader()Document document reader.read(xml)Element ro

封装获取的xml节点
SAXReader reader = new SAXReader();
Document document = reader.read(xml);
Element root = document.getRootElement(); // xml根节点
String total=root.elementText("total");
List<Node> doc = root.selectNodes("doc"); // xml
if (doc != null && doc.size() > 0) {
logger.info("【通过第三方查询返回结果为】" + doc.size() + "条");
for (Node obj : doc) {
RecommendInfo p = new RecommendInfo();
Node bizid = obj.selectSingleNode("bizid");
if (bizid != null)
p.setBizid(bizid.getText());
Node name = obj.selectSingleNode("name");
if (name != null)
p.setName(name.getText());
Node tel = obj.selectSingleNode("tel");
if (tel != null)
p.setTel(tel.getText());
Node addr = obj.selectSingleNode("addr");
if (addr != null)
p.setAddr(addr.getText());
Node desc = obj.selectSingleNode("desc");
if (desc != null)
p.setDesc(desc.getText());
Node dist = obj.selectSingleNode("dist");
if (dist != null)
p.setDist(dist.getText());
Node mapxy = obj.selectSingleNode("mapxy");
if (mapxy != null)
p.setMapxy(mapxy.getText());
Node detail = obj.selectSingleNode("detail");
if (detail != null)
p.setDetail(detail.getText());
list.add(p);
}
返回list ,并且把解析到的xml节点里的值存放到对应的bean里

热点排行