我正在嘗試使用最新的JDOM包生成XML文檔。我遇到了根元素和名稱空間的問題。我需要生產這根元素:JDOM中的名稱空間(默認)
<ManageBuildingsRequest
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">
我用這個代碼:
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後的下一個元素都有默認的命名空間爲好,它打破了驗證:
<customer xmlns="">
任何幫助?感謝您的時間。
你能後的代碼生成您的XML嗎? – GETah