xml怎么读数据来?
<?xml version="1.0" encoding="UTF-8"?>
<urlset count="118">// count="118" 北京地区有118个团购信息
<url id="1">// id="1" 北京第1团购产品
<loc>http://beijing.lashou.com/deal/114728.html</loc>
<data>
<display>
<website>拉手网</website>
<cate>休闲</cate>
<siteurl>http://beijing.lashou.com/</siteurl>
<city>北京</city>
<gid>114728</gid>
<title><![CDATA[ 仅售39元!原价70元“中国航空博物馆”周末体验套票一张:模拟射击体验一次(20发)+登歼-6战机体验(自带相机)+空中医院+飞行头盔+飞行服装!本套票仅限周六至周日使用!体验射击快感和翱翔天空的酣畅淋漓!]]></title>
<image>http://d1.lashouimg.com/lasho_pic/go/00/00/11/47/114728</image>
<startTime>1307635200</startTime>
<endTime>1307894400</endTime>
<value>70.00</value>// value 该商品市场价
<price>39.00</price>// price 该商品折扣价
<rebate>5.6</rebate>// rebate 该商品的折扣
<bought>79</bought>// bought 该商品的购买人数
<detail>
<![CDATA[ 扛起战枪,体验激情四射的枪林弹雨;坐上战机,给孩子们一个无与伦比的军事体验。]]></detail>
<shops>
<shop>
<name><![CDATA[ 中国航空博物馆]]></name>
<tel><![CDATA[ ]]></tel>
<addr><![CDATA[ 昌平区小汤山中国航空博物馆]]></addr>
</shop>
</shops>
</display>
</data>
</url>
</urlset>
public List readXML(String xml) throws JDOMException, IOException{
List<Map<String,String>> list=new ArrayList<Map<String,String>>();
Map<String,String> map=new HashMap<String,String>();
Document document = null;
ByteArrayInputStream xmlStream = null;
try{
xmlStream=new ByteArrayInputStream(xml.getBytes("gb2312"));
}
catch(UnsupportedEncodingException uee){
uee.printStackTrace();
}
if(xmlStream!=null){
SAXBuilder saxBuilder=new SAXBuilder();
document=saxBuilder.build(xmlStream);
Element root=document.getRootElement();
System.out.println(root.getName());
list=this.xmlToMap(root, list,map);
}
return list;
}
public List<Map<String,String>> xmlToMap(Element root,List<Map<String,String>> list,Map<String,String> map){
List children=root.getChildren();
Iterator it = children.iterator();
while(it.hasNext()){
Element child = (Element) it.next();
if(map.containsKey("loc")){
map=new HashMap<String,String>();
}
String name = child.getName();
System.out.println(name+"***"+child.getText());
// 如果有子节点,则递归调用
if (child.getChildren().size() > 0)
{
xmlToMap(child, list,map);
}else{
if(child.getText()!=null && !child.getText().equals("")){
map.put(name, child.getText());
}
}
list.add(map);
}
}
return list;