JDOM解析XML

待解析的XML

<?xml version="1.0" encoding="utf-8"?>
<musices>
	<music>
		<name>Hello</name>
		<size>8622</size>
	</music>
	<music>
		<name>World</name>
		<size>300</size>
	</music>
</musices>	

 

	SAXBuilder builder = new SAXBuilder();
		Document doc = builder.build(new File("E:\\music.xml"));
		Element foo =  doc.getRootElement();
		List allChildren = foo.getChildren();
		for(int i=0;i<allChildren.size();i++) {
		System.out.print("歌曲名称:" + ((Element)allChildren.get(i)).getChild("name").getText());
		System.out.println("歌曲大小:" + ((Element)allChildren.get(i)).getChild("size").getText());}
 同时导入jdom.jar

你可能感兴趣的:(dom解析xml)