[jdom-interest] jarv filter & jdom

Bradley S. Huffman hip at a.cs.okstate.edu
Thu Mar 31 07:24:26 PST 2005


Carlos Pita writes:

> I need to do relax ng validation. I'm using msv/jarv and jdom.
> Simple alternatives are to validate first and then create the
> jdom document, or to get sax events or a dom from the jdom
> document and then validating.
> 
> But jarv also offers a filter which can be put
> between the sax reader and the sax content handler. I guess
> that this is the best alternative regarding performance (cause
> parsing is done only once and there is only one in-memory
> representation of the document model). The problem is that
> I can't see how to plug this filter into the SAXBuilder
> via the public api. There is a protected method that perhaps
> could be overridden:
> 
>   protected XMLReader createParser();
> 
> The following worked for me, but maybe is a little kludgy:
>  
>   class FilteredSAXBuilder extends SAXBuilder {
> 
>     private VerifierFilter filter = null;
>     
>     public void setFilter(VerifierFilter filter) {
>         this.filter = filter;
>     }
>         
>     protected XMLReader createParser() throws JDOMException {
>         XMLReader parser = super.createParser();
>         filter.setParent(parser);
>         return filter;
>     }
>   }
> 
> Another way could be via XMLReaderFactory.
> I'm not sure about what to do. Could you give me some advice?

Since VerifierFilter implements org.xml.sax.XMLFilter you could also do

    SAXBuilder builder = new SAXBuilder(....);
    builder.setXMLFilter(verifierFilter);

Brad


More information about the jdom-interest mailing list