[jdom-interest] remove comments

Jason Hunter jhunter at xquery.com
Tue Aug 24 15:21:24 PDT 2004


If you want the output to have no comments, just override XMLOutputter's 
printComment() method to be a no-op.

To make a live change, you need to recurse.  Your code below only does 
one level.  There was easy recursion added I think in b10, but you can 
do it yourself easily enough.

-jh-

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.
> 
> I've been trying approaches like:
> 
>       ContentFilter filter =  new ContentFilter();
>       filter.setCommentVisible(true);
>       List comments = doc.getContent(filter);
>       doc.removeContent((Comment)comments.get(0));
> 
> but this seems to neither remove the comment, nor are all the comments 
> in the list.
> 
> Thanks!
> 
> -- john
> 
> =====================================================
> John Cartwright
> Associate Scientist
> Geospatial Data Services Group
> CIRES, National Geophysical Data Center/NOAA
> (303) 497-6284
> John.C.Cartwright at noaa.gov
> =====================================================
> 
> _______________________________________________
> To control your jdom-interest membership:
> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com
> 


More information about the jdom-interest mailing list