码迷,mamicode.com
首页 > 其他好文 > 详细

xml合并问题,多个xml拼接

时间:2018-04-01 22:58:56      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:[]   accept   pattern   合并   for   flow   org   java   system   

<payment>
    <AuditFileVersion>信息</AuditFileVersion>
    <telephone>销方</telephone>
</payment>
<payment>
    <AuditFileVersion>信息</AuditFileVersion>
    <telephone>销方</telephone>
</payment>

多个上边的xml合并为下边的xml:

<all>
<bb>
<payment>
    <AuditFileVersion>信息</AuditFileVersion>
    <telephone>销方</telephone>
</payment>
<payment>
    <AuditFileVersion>信息</AuditFileVersion>
    <telephone>销方</telephone>
</payment>
</bb>
</all>

实现如下:

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);
List<Element> elements = read.getDocument().getRootElement().elements();
for (Element emt : elements) {
flows.add(emt.detach());
}
}
}
System.out.println(rootDoc.asXML());
}
}

 

xml合并问题,多个xml拼接

标签:[]   accept   pattern   合并   for   flow   org   java   system   

原文地址:https://www.cnblogs.com/hxjj/p/8688570.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!