封装获取的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里

你可能感兴趣的:(bean,xml,document,element)