Re: Resetting the Root Element

Laurent Bihanic <[email protected]>
Newsgroups gmane.comp.java.jdom.general
Message-ID <[email protected]>
Jason Hunter wrote:
>> 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.)

Yes but the interest of removeContent() in the present case is that it returns 
the list of the detached nodes. This is not the case for setAttributes() which 
returns the current element; the detached attributes are then lost.
I was looking for a single-line-of-code attribute transfer, just as I can do 
with content.

Laurent

_______________________________________________
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.