带解析的XML
<?xml version="1.0" encoding="utf-8"?> <musices> <music> <name>Hello</name> <size>8622</size> </music> <music> <name>World</name> <size>200</size> </music> </musices>
File f = new File("E:\\music.xml");
SAXReader reader = new SAXReader();
Document doc = reader.read(f);
Element root = doc.getRootElement();
Element foo;
for (Iterator i = root.elementIterator("music"); i.hasNext();) {
foo = (Element) i.next();
System.out.print("歌曲名称:" + foo.elementText("name"));
System.out.println(" 歌曲大小:" + foo.elementText("size"));}
需要的dom4j.jar