日期:2014-05-17 浏览次数:20725 次
public static void templateConfigInit() { Document document = getDocument("/templateConfig.xml");// 文档对象 Element root = document.getRootElement();// 根节点 Element config = root.element("config");// config节点 for (Iterator<Element> it = config.elementIterator(); it.hasNext();) { Element el = it.next(); if (COMPANY_LEVEL_TEMPLATE.equals(el.getName())) { for (Iterator<Element> itc = el.elementIterator(); itc.hasNext();) { Element elc = itc.next(); setTemplate(elc, COMPANY_LEVEL_TEMPLATE); } } else if (DIVISION_LEVEL_TEMPLATE.equals(el.getName())) { for (Iterator<Element> itc = el.elementIterator(); itc.hasNext();) { Element elc = itc.next(); setTemplate(elc, DIVISION_LEVEL_TEMPLATE); } } } log.info("load [templateConfig.xml] completed"); }
------解决方案--------------------
dom4j比较好用
使用dom4j创建catalog.xml
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.XMLWriter;
import java.io.*;
public class XmlDom4J{
public void generateDocument(){
Document document = DocumentHelper.createDocument();
Element catalogElement = document.addElement("catalog");
catalogElement.addComment("An XML Catalog");
catalogElement.addProcessingInstruction("target","text");
Element journalElement = catalogElement.addElement("journal");