import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
 
public class Demo1{
    public static void main (String [] args)
 
throws IOException, DocumentException
 
{
//1.先指定文件,获取输入流
FileInputStream fis = new FileInput Stream("c:Demo1.xml");
//2.创建xml读取对象
SAXReader sr = new SAXReader();
//3.读取并得到文档对象
Document doc = sr.read(fis);
//4.通过文档获取根元素
Element root = doc.getRootElement();
//5.开始解析元素
System.out.println(root.getName());
fis.close;//不要忘记关闭油
//将根里的元素放进集合里
LIst <Element>  es = root.elements();
//遍历这个集合
for(int i=0; i<es.size();i++){
Element book = es.get(i);
System.out.println(book.attribute());//属性
System.out.printlin(book.element("name"));
}
}
}