使用dom4j解析XML

一、引用jar包:dom4j

二、具体实现代码

//使用dom4j解析返回的xml
SAXReader reader = new SAXReader();
Document doc = reader.read(new ByteArrayInputStream(xmlResult.getBytes("UTF-8")));
Element element = doc.getRootElement();
List<Element> childElementList = element.elements();

for(Element tmp:childElementList ){
  if(tmp.attributeValue("sqlFormula") != null){
	Map<String,String> columnMap = new HashMap<String,String>();
	columnMap.put("columnName", tmp.attributeValue("name"));
	columnMap.put("name", tmp.attributeValue("sqlFormula"));
	columnMapList.add(columnMap);
  }else{
	getColumnName(tmp.elements(),columnMapList);
  }
}
原文地址:https://www.cnblogs.com/JoeyWong/p/5955100.html