[jdom-interest] Filtering comments
Jason Hunter
jhunter at xquery.com
Fri Mar 19 10:03:39 PST 2004
Here's how I'd do it:
In the latest CVS, the factory impls have an addContent(Parent, Content)
method called to add the content to the parent. Subclass the default
factory, override addContent() so if the Content is a Comment, the call
just returns without doing the add. Then pass your factory to the
builder. You could do this trivially using an anonymous inner class.
-jh-
Rolf Lear wrote:
> There is no current way to do that in JDom that I know of.
>
> Jason, I through this through, and decided to write a new "Builder". It may
> just be useful to others. Please consider it as a "contribution".
>
> Basically I have written org.jdom.input.FilteredBuilder. The code is
> attached. It is VERY simple. So simple I have not even tested it
> properly....
>
> Used like:
>
> Document doc = new SAXBuilder().build("....document source...");
> ContentFilter filter = new ContentFilter();
> filter.setCommentVisible(false);
> Document filtered = new FilteredBuilder(filter).build(doc);
>
> Useful? I use Clones to do the hard work, so it is somewhat memory
> expensive.
>
> Maybe I missed something already in JDom.
>
> Rolf
>
> -----Original Message-----
> From: Rocchi Cesare [mailto:rocchi at itc.it]
> Sent: Friday, March 19, 2004 5:13 AM
> To: jdom-interest at jdom.org
> Subject: [jdom-interest] Filtering comments
>
>
> Hi,
>
> just wondering how to filter out comments from an xml file/string.
> Any idea? Browsed the archive but have not been lucky.
>
> Thanks,
>
> -c.
More information about the jdom-interest
mailing list