首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > XML SOAP >

dom4j生成xml有关问题~

2012-03-29 
dom4j生成xml问题~ 高手进~[codeJava][/code]Document doc org.dom4j.DocumentHelper.createDocument()

dom4j生成xml问题~ 高手进~
[code=Java][/code]
  Document doc = org.dom4j.DocumentHelper.createDocument();
Element process = doc.addElement("process");
process.addAttribute("xmlns", "http://drools.org/drools-5.0/process");
process.addAttribute("xmlns:xs", "http://www.w3.org/2001/XMLSchema-instance");
process.addAttribute("xs:schemaLocation", "http://drools.org/drools-5.0/process drools-processes-5.0.xsd");

生成的结果是:
[code=XML][/code]
<process xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:schemaLocation="http://drools.org/drools-5.0/process drools-processes-5.0.xsd">
</process>

我想要的结果是:
[code=XML][/code]
<process xmlns="http://drools.org/drools-5.0/process"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="http://drools.org/drools-5.0/process drools-processes-5.0.xsd">
</process>


[解决办法]

Java code
        Document doc = DocumentHelper.createDocument();        Element root = doc.addElement("process");        Element ns = root.addNamespace("","http://drools.org/drools-5.0/process");        Element xs = root.addNamespace("xs","http://www.w3.org/2001/XMLSchema-instance");        Element sl = root.addAttribute("xs:schemaLocation","http://drools.org/drools-5.0/process drools-processes-5.0.xsd"); 

热点排行