I want to add xmlns:atom to the root element of an XML file, the file already exists, I just want to modify it by adding the adding xmlns. The rest of the files is to be left unchanged. As an example, I have <rss version="2.0"> in file and I want to convert it in to <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> using JDOM. How can I do this?
I want to add xmlns:atom to the root element of an XML file, the
Share
Once you have the input file loaded as a JDOM Document, you can:
Then, when you output the document it will have the additional namespace declaration.
Make sure you use the right URI for your Namespace… not ‘…’ …
See the documentation for addNamespaceDeclaration: