[jdom-interest] Important proposal: Element/Document changes

Jason Hunter jhunter at acm.org
Thu Jul 27 01:52:27 PDT 2000


> OK, I see what you are getting at now.
> 
> So to achieve;
> 
>         <!-- comment -->
>         <root/>
>         <!-- comment -->
> 
> You would write;
> 
>         Document doc = new Document();
>         Comment comment = new Comment("comment");
>         Element element = new Element("root");
> 
>         doc.addContent(comment);
>         doc.addContent(element);
>         doc.addContent(comment);
> 
> Fine happy with that.

You could have issues with double use of the Comment instance should you
get deep into manipulating the document, but basically yes.

> But what if you want to change the "root" element ? 

How about just
  doc.setRootElement(newRoot);

setRootElement() can be smart enough to look for the sole element and
replace it.

-jh-



More information about the jdom-interest mailing list