Special character problem when Jdom generates xml file

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" ); // Add the root node to the document; Document Doc = new Document (root); CDATA text = null ; // Create node 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); // Indentation effect of xml file Format format = Format.getPrettyFormat (); XMLOutputter XMLOut = new XMLOutputter(format); XMLOut.output(Doc, new FileOutputStream(path)); return path; }

compile 'org.jdom:jdom:1.1.3'

Guess you like

Origin www.cnblogs.com/liangblog/p/12674570.html