Jdom生成xml文件时的特殊字符问题

import org.jdom.CDATA;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;

    

public static String toXML(String path) throws IOException { Element root = new Element("ADI"); // 将根节点添加到文档中; Document Doc = new Document(root); CDATA text = null; // 创建节点 Element elements = new Element("Objects"); Element title = new Element("title"); title.setAttribute("Name", "title"); text = new CDATA(""); text.setText("125722130016"); title.setContent(text); object.addContent(title); Element vodfile = new Element("vodfile"); vodfile.setAttribute("Name", "vodfile"); vodfile.setText("<![CDATA[北125722130016.mp4]]>"); object.addContent(vodfile); root.addContent(elements); // 使xml文件 缩进效果 Format format = Format.getPrettyFormat(); XMLOutputter XMLOut = new XMLOutputter(format); XMLOut.output(Doc, new FileOutputStream(path)); return path; }

compile 'org.jdom:jdom:1.1.3'

猜你喜欢

转载自www.cnblogs.com/liangblog/p/12674570.html
今日推荐