信息 销方
信息 销方
多个上边的xml合并为下边的xml:
信息 销方 信息 销方
实现如下:
import org.dom4j.Document; import org.dom4j.Element; import org.dom4j.io.SAXReader; import java.io.File; import java.io.FileFilter; import java.util.List; import java.util.regex.Pattern; /** * @author Cyhui. */ public class aaa { public static void main(String[] args) throws Exception { SAXReader saxReader = new SAXReader(); String tube = "F:\\xmll\\root.xml"; Document rootDoc = saxReader.read(new File(tube)); Element parent = rootDoc.getRootElement(); Element flows = parent.element("bb"); File file = new File("F:\\xmll"); if (file.exists()) { File[] files = file.listFiles(new FileFilter() { public boolean accept(File pathname) { String fileName = pathname.getName(); String pattern = "^ff.*.xml$"; boolean matches = Pattern.matches(pattern, fileName); return matches; } }); for (File f : files) { Document read = saxReader.read(f); Listelements = read.getDocument().getRootElement().elements(); for (Element emt : elements) { flows.add(emt.detach()); } } } System.out.println(rootDoc.asXML()); } }