日期:2014-05-19  浏览次数:20761 次

jdom xml命名空间 如何创建 节点呀 在线 谢谢了
<root>
<login user="admin" pass="12345"/>
<video:chn inum="1" onum="0"/>
</root>


这种如何创建呀 谢谢了

------解决方案--------------------
Java code

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));
    }
}