如题
<?xml version="1.0" encoding="utf-8" ?>
<root>
<province data="北京">
<city>
<cityid>101010100</cityid>
<cityname>北京</cityname>
</city>
<city>
<cityid>101010200</cityid>
<cityname>海淀</cityname>
</city>
<city>
<cityid>101010300</cityid>
<cityname>朝阳</cityname>
</city>
<city>
<cityid>101010400</cityid>
<cityname>顺义 </cityname>
</city>
</province>
</root>
------解决方案--------------------
这还有什么好说的么?
------解决方案--------------------
public class province
{
private String data;
private List<City> city;
}
这个还有什么好说了 sax 或者pull自己解析吧,很清晰
------解决方案--------------------
用dom4j吧之前做java开发时用这个 很简单 http://www.cnblogs.com/macula/archive/2011/07/27/2118003.html可以看看
------解决方案--------------------
我随便写了个 你下个jar包可以直接用 Document doc = null;
SAXReader sax = new SAXReader();
try {
doc = sax.read(new File("d://aaa.xml"));
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Element root = doc.getRootElement();
List<Map<String, String>> dbConnections = new ArrayList<Map<String, String>>();
Iterator<Element> rootIter = root.elementIterator();