java中jdom,java – JDOM中的命名空间(默认)
我正在嘗試使用最新的JDOM包生成
XML文檔.我遇到了根元素和命名空間的問題.我需要生成這個(gè)根元素:
xmlns="http://www.energystar.gov/manageBldgs/req"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.energystar.gov/manageBldgs/req
http://estar8.energystar.gov/ESES/ABS20/Schemas/ManageBuildingsRequest.xsd">
我用這個(gè)代碼:
Element root = new Element("ManageBuildingsRequest");
root.setNamespace(Namespace.getNamespace("http://www.energystar.gov/manageBldgs/req"));
Namespace XSI = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
root.addNamespaceDeclaration(XSI);
root.setAttribute("schemaLocation", "http://www.energystar.gov/manageBldgs/req http://estar8.energystar.gov/ESES/ABS20/Schemas/ManageBuildingsRequest.xsd", XSI);
Element customer = new Element("customer");
root.addContent(customer);
doc.addContent(root); // doc jdom Document
但是,ManageBuildingsRequest之后的下一個(gè)元素也具有默認(rèn)命名空間,這會(huì)破壞驗(yàn)證:
有幫助嗎?感謝您的時(shí)間.
總結(jié)
以上是生活随笔為你收集整理的java中jdom,java – JDOM中的命名空间(默认)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux判断内存并释放,linux 内
- 下一篇: 在Bootstrap中使用类的按钮类型