---
title: "DOM4J解析XML"
author: "HeLinHang"
date: "2011-08-16T21:47:53Z"
tags: []
categories: ["编程语言"]
slug: "dom4j-xml"
draft: false
lastmod: "2011-08-16T21:47:53Z"
id: 1150817
url: "https://ibook.iteye.com/blog/1150817"
---

带解析的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