1.新建一个 dept.xml 文件
7
IT
8
行政
9
会计
2.新建一个测试类 : com.xml4.TestXmlToList
package com.xml4;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import com.dao.DeptDao;
import com.dao.DeptDaoImpl;
import com.entity.Dept;
public class TestXmlToList
{
private static List deptList=new ArrayList();
public static void main(String[] args)
{
//将 dept.xml 转化成 List
xmlToList("dept.xml");
//将 deptList 存入 库
DeptDao deptDao=new DeptDaoImpl();
deptDao.add(deptList);
}
public static void xmlToList(Stri