1

I want to add namespace to an xml file using java program. So how can I add namespace to an xml file using java

Thanks Bapi

Deepak
  • 439
  • 1
  • 13
  • 27
  • possible duplicate of [Creating an XML document using namespaces in Java](http://stackoverflow.com/questions/528312/creating-an-xml-document-using-namespaces-in-java) – Guido Nov 17 '11 at 16:21
  • Similar SO thread [Creating an XML document using namespaces in Java](http://stackoverflow.com/questions/528312/creating-an-xml-document-using-namespaces-in-java) – TStamper Apr 22 '09 at 13:46

1 Answers1

1

Whit JDom

add an URI to xmlns in root element

Namespace ns = Namespace.getNamespace("yourURI");
Element root = new Element("someName", ns);

add any namespace

Namespace ns = Namespace.getNamespace("someName", "someValue");
Element yourElement = new Element("someName", ns);
root.addChild(yourElement);
Document doc = new Document(root);