class="java" name="code"> import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import org.dom4j.Document; import org.dom4j.io.SAXReader; public class XmlUtil { public static Document readXml(String filePath) { InputStream in = null; Document doc = null; // 解析xml文档内容 try { SAXReader reader = new SAXReader(); // 获取到xml文件 in = new FileInputStream(new File(filePath)); doc = reader.read(in); } catch (Exception e) { System.out.println("XMLUtil.readXml error: " + e); return null; } finally { try { in.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return doc; } }