I am trying to create an XML document using the latest JDOM package. I'm having problems with the root element and namespaces. I need to create this root element:
<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">
I am using this code:
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);
However, the following element after ManageBuildingsRequest also has a default namespace that violates validation:
<customer xmlns="">
Any help? Thank you for your time.
jn1kk source share