Skip to content

Instantly share code, notes, and snippets.

@suxiaogang
Created June 5, 2013 08:08
Show Gist options
  • Save suxiaogang/5712340 to your computer and use it in GitHub Desktop.
Save suxiaogang/5712340 to your computer and use it in GitHub Desktop.
Set Namespace In JDom
public void write(Writer writer) throws Exception {
Element rootElement = new Element("ABC");
namespace = Namespace.getNamespace("","http://abc.com/abc_1_0_0");
rootElement.setNamespace(namespace);
rootElement.addNamespaceDeclaration(namespace);
Namespace ns = Namespace.getNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
rootElement.addNamespaceDeclaration(ns);
rootElement.setAttribute("schemaLocation", "http://abc.com/abc.xsd", ns);
this.writeDomain(rootElement);
Document document = new Document(rootElement);
DocumentHelper.write(document, writer);
namespace = rootElement.getNamespace();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment