/* * RemoveNamespaceDeclarationTest.java * * trying to figure out how to remove a namespace from adocument? */ //import java.net.*; //import java.util.List; //import java.util.Iterator; import java.io.FileInputStream; //import java.io.FileOutputStream; import org.jdom.input.SAXBuilder; //import org.jdom.output.XMLOutputter; import org.jdom.Document; import org.jdom.Element; import org.jdom.Namespace; public class RemoveNamespaceDeclarationTest { public static void main (String args[]) { RemoveNamespaceDeclarationTest test = new RemoveNamespaceDeclarationTest(); test.removeNamespace( test.buildDocument("C:\\jdom_help\\test.xml") ); } public Document buildDocument(String path){ // parse the in file Document doc = null; try{ SAXBuilder builder = new SAXBuilder(); doc = builder.build(new FileInputStream(path)); }catch(Exception e){ System.err.println(e); } return doc; } public Document removeNamespace(Document doc){ // remove the namespace on the root of the document Element e = doc.getRootElement(); String s = e.getNamespaceURI(); System.out.println("before: " + e.getNamespace()); e.removeNamespaceDeclaration(Namespace.getNamespace(s)); System.out.println("after: " + e.getNamespace()); return doc; } }