1.问题是:xmlns属性为什么没有加进去呢?
直接放代码(结果图在后面)
public static void main(String[] args){
XMLWriter writer=null;
FileOutputStream out=null;
try {
Document doc = DocumentHelper.createDocument();
Element Cole = doc.addElement("Cole");
Cole.addAttribute("xmlns","http://www.gzrst.gov.cn/DA");
Cole.addAttribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance");
Cole.addAttribute("xsi:schemaLocation","http://www.gzrst.gov.cn/DA SIP.xsd");
out = new FileOutputStream("d:/test2.xml");
OutputFormat format = OutputFormat.createPrettyPrint();
format.setEncoding("utf-8");
writer = new XMLWriter(out,format);
writer.write(doc);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (writer != null) {
try {
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (out != null) {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
2.结果: