Hey Chris

Sorry for the delay answering this - I wanted to prove to myself this
approach works before answering.

The trick is to use VerifierFilter from MSV which is-a XMLFilter so that
validation can be done at the same time as dom4j parsing. The filter can be
installed using this code...

        VerifierFilter filter = verifier.getVerifierFilter();
        SAXReader reader = new SAXReader();
        reader.setXMLFilter( filter );

To test this works I've added a new sample program to CVS at
dom4j/src/samples/validate/JARVDemo2.java that uses a VerifierFilter to
validate the XML against any schema (DTD, RelaxNG, XML Schema etc.) while
parsing a dom4j document. Works a treat.

This technique is described (from a SAX perspective) in the JARV.html
document in the MSV distribution.

James
----- Original Message -----
From: "Christopher M. Golden" <[EMAIL PROTECTED]>
To: "DOM4J User's Mailing List" <[EMAIL PROTECTED]>
Sent: Monday, February 18, 2002 3:46 PM
Subject: Re: [dom4j-user] Problems validating with schema


Is there any way to perform Validation this way while reading in the
document from an xml file?  I looked at SAXReader and I didn't see any way
to implement the ValidatorHandler.  Am I just missing something or do I
really have to parse in the XML document in full and then write it out to
validate it by a schema?  This seems a bit much...  TIA!


Chris Golden


On Sat, 16 Feb 2002 10:25:25 -0000, James Strachan wrote:
>Hi Chris
>
>The MSV method you're looking at probably takes a W3C Node interface
>rather than an org.dom4j.Node interface.
>
>There's a sample program in the dom4j/src/validate/JARVDemo.java that
>demonstrates how to use MSV with dom4j. The trick is to use a
>VerifierHandler and a dom4j SAXWriter to pipe SAX events into MSV.
>e.g.
>adding these few methods instead of the "return
>verifier.verify(doc);" line
>
>
> VerifierHandler handler = verifier.getVerifierHandler();
> SAXWriter writer = new SAXWriter( handler );
> writer.write( document );
>
>James


_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user


_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to