package com.test.opeZip;
import org.dom4j.*;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;
public class OpeXml {
public static Document document = null;
public static void main(String[] args) throws IOException, DocumentException {
String xmlPath = "E:\\测试.xml";
//创建xml
createXML(xmlPath);
//读取xml
readXml(xmlPath);
}
//创建一个xml文件,xmlPath为一个xml文件路径,后缀为xml
public static void createXML(String xmlPath) throws IOException {
File xmlFile = new File(xmlPath);
if(!xmlFile.exists()){
xmlFile.createNewFile();
}
document = DocumentHelper.createDocument();
//创建根节点
Element root = document.addElement("root");
//为根节点增加属性
root.addAttribute(
Java创建xml以及解析xml(dom4j-1.6.1.jar)
最新推荐文章于 2021-03-08 06:28:53 发布