<?xml version="1.0" encoding="utf-8"?>
<country name="中国">
<province name="吉林省">
<city>
长春
</city>
<city>
吉林
</city>
<city>
四平
</city>
<city>
松原
</city>
<city>
通化
</city>
</province>
<province name="山东省">
<city>
济南
</city>
<city>
青岛
</city>
<city>
威海
</city>
<city>
烟台
</city>
</province>
</country>
public Map getMes() throws DocumentException {
HashMap<String, List> info = new HashMap<String, List>();
SAXReader reader = new SAXReader();// 获取解析对象
Document document = reader.read("src/cn/it/db/province.xml");
Element root = document.getRootElement();// 得到根节点
List provinces = root.elements();// 得到字节点集合
for (int i = 0; i < provinces.size(); i++) {
List<String> cityVal = new ArrayList<String>();
Element province = (Element) provinces.get(i);
String provinceVal = province.attributeValue("name");// 获取省名称
List cities = province.elements();
for (int j = 0; j < cities.size(); j++) {
Element city = (Element) cities.get(j);// 获取城市节点
cityVal.add(city.getTextTrim());
}
info.put(provinceVal, cityVal);
}
return info;
}