[jdom-interest] remove comments

Per Norrman per.norrman at austers.se
Wed Aug 25 00:36:21 PDT 2004


Hi,

from my personal tool box:

     public static void removeComments(List l) {
         for (Iterator i = l.iterator(); i.hasNext();) {
             Object node = i.next();
             if (node instanceof Comment) {
                 i.remove();
             } else if (node instanceof Element) {
                 removeComments(((Element)node).getContent());
             }
         }
     }

     public static void removeComments(Document doc) {
         removeComments(doc.getContent());
     }

/pmn

John C Cartwright wrote:

> Hello All,
> 
> I'm using jdom b9 and trying to find a elegant way to remove all comment 
> nodes from a document.  I seem to be thrashing about though, and would 
> appreciate some direction.
> 



More information about the jdom-interest mailing list