日期:2014-05-19 浏览次数:20761 次
import org.jdom.Document; import org.jdom.Element; import org.jdom.Namespace; import org.jdom.output.Format; import org.jdom.output.XMLOutputter; public class jdom { public static void main(String[] args){ Element root = new Element("root"); Element elements = new Element("login"); elements.setAttribute("user","admin"); elements.setAttribute("pass","12345"); root.addContent(elements); Element elements1 = new Element("chn"); elements1.setNamespace(Namespace.getNamespace("video","https://123")); elements1.setAttribute("inum","1"); elements1.setAttribute("onum","0"); root.addContent(elements1); Format format = Format.getPrettyFormat(); XMLOutputter output = new XMLOutputter(format); System.out.println(output.outputString(root)); } }