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>
[解决办法]
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");