Re: Resetting the Root Element

Jason Hunter <[email protected]>
Newsgroups gmane.comp.java.jdom.general
Message-ID <[email protected]>
Laurent Bihanic wrote:
> Hi,
> 
> Sebastian Hinterwälder wrote:
>> Now I want to set a different root element using JDOM. I already tried 
>> it by cloning the whole document but this doesn't work. A different 
>> solution for me would also be removing the namespaces from the root. I 
>> am quite new to JDOM - so I hope someone knows a solution!
> 
> You have to create a new root element and detach content from the old 
> root to add it to the new root :
>     Element newRoot = new Element(...);
>     newRoot.setContent(oldRoot.removeContent());
> 
> Unfortunately, there is no Element.removeAttributes() method. So you'll 
> probably have to iterate on the old root's attribute list to detach each 
> attribute (using Iterator.remove()) and add it to the new root.
> Any better way, someone ?

You can do elt.setAttributes(null).

(Or pass an empty list.)

-jh-
_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.