dom4j读取两个xml文件 然后 copy
来源:互联网 发布:命中双色球软件 编辑:程序博客网 时间:2024/05/29 16:30
package chapter;
import java.io.File;
import java.io.FileWriter;
import java.util.Iterator;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;
public class XMLReader {
public static void main(String[] args) {
long lasting = System.currentTimeMillis();
try {
File f = new File("F:/io/client_side.xml");
File f1 = new File("F:/io/group_sername.xml");
SAXReader reader = new SAXReader();
Document doc = reader.read(f);
Element root = doc.getRootElement();
Document doc1 = reader.read(f1);
Element root1 = doc1.getRootElement();
OutputFormat outFmt = new OutputFormat();
XMLWriter xmlWriter = null;
FileWriter fw = null;
Element foo;
Element foo1;
for (Iterator i = root.elementIterator("serverGroup"); i.hasNext();) {
foo = (Element) i.next();
System.out.println(foo.attributeValue("name").trim());//dcz dy1
System.out.println(foo.getStringValue().trim());
System.out.println("走到这1");
}
for (Iterator i = root1.elementIterator("Server"); i.hasNext();) {
foo1 = (Element) i.next();
System.out.println(foo1.elementText("Hostname"));
System.out.println(foo1.elementText("Port"));
System.out.println("这也走了****");
}
System.out.println("走到这2");
fw=new FileWriter("F:/io/copyclient_side.xml");
//fw.append("");
System.out.println("走到这3");
outFmt=new OutputFormat(" ",true);
System.out.println("走到这4"+"f="+outFmt);
xmlWriter = new XMLWriter(fw, outFmt);
System.out.println("走到这5");
xmlWriter.write(doc);
System.out.println("走到这6");
fw.flush ();
xmlWriter.flush ();
xmlWriter.close ();
System.out.println("走到这7");
fw.close ();
} catch (Exception e) {
System.out.println("baocuo l ");
e.printStackTrace();
}
}
}
import java.io.File;
import java.io.FileWriter;
import java.util.Iterator;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;
public class XMLReader {
public static void main(String[] args) {
long lasting = System.currentTimeMillis();
try {
File f = new File("F:/io/client_side.xml");
File f1 = new File("F:/io/group_sername.xml");
SAXReader reader = new SAXReader();
Document doc = reader.read(f);
Element root = doc.getRootElement();
Document doc1 = reader.read(f1);
Element root1 = doc1.getRootElement();
OutputFormat outFmt = new OutputFormat();
XMLWriter xmlWriter = null;
FileWriter fw = null;
Element foo;
Element foo1;
for (Iterator i = root.elementIterator("serverGroup"); i.hasNext();) {
foo = (Element) i.next();
System.out.println(foo.attributeValue("name").trim());//dcz dy1
System.out.println(foo.getStringValue().trim());
System.out.println("走到这1");
}
for (Iterator i = root1.elementIterator("Server"); i.hasNext();) {
foo1 = (Element) i.next();
System.out.println(foo1.elementText("Hostname"));
System.out.println(foo1.elementText("Port"));
System.out.println("这也走了****");
}
System.out.println("走到这2");
fw=new FileWriter("F:/io/copyclient_side.xml");
//fw.append("");
System.out.println("走到这3");
outFmt=new OutputFormat(" ",true);
System.out.println("走到这4"+"f="+outFmt);
xmlWriter = new XMLWriter(fw, outFmt);
System.out.println("走到这5");
xmlWriter.write(doc);
System.out.println("走到这6");
fw.flush ();
xmlWriter.flush ();
xmlWriter.close ();
System.out.println("走到这7");
fw.close ();
} catch (Exception e) {
System.out.println("baocuo l ");
e.printStackTrace();
}
}
}
阅读全文
0 0
- dom4j读取两个xml文件 然后 copy
- xml文件读取-dom4j
- dom4j读取xml文件
- dom4j读取xml文件
- dom4j读取xml文件
- Dom4j读取XML文件
- Dom4j读取xml文件
- DOM4J读取XML文件
- DOM4J读取XML文件
- Dom4j读取Xml文件
- dom4j读取xml文件
- Dom4j读取xml文件
- dom4j读取xml文件例子
- 使用dom4j读取xml文件
- 使用DOM4j读取xml文件
- 使用Dom4j读取xml文件
- 利用dom4j读取xml文件
- DOM4j SAXReader 读取XML文件
- BASIC-6 基础练习 杨辉三角形
- 第八周 项目二 建立链串的算法库
- Vue需要注意的地方
- CNN QA(Question and Answer)问答的theano和tensorflow代码
- Web 前端的路该怎么走?
- dom4j读取两个xml文件 然后 copy
- 安卓权限工具类
- 前端工具
- tomcat原理之setclasspath.bat
- 运算符
- 第十一项目二 操作用邻接表存储的图
- 书籍
- iOS唤起一个APP
- DeepFM:深度学习算法助力华为应用市场APP推荐