SAX: perform valisation after passing through filter?

T

Tobias Noebauer

hello,

I have to process an xml-file that uses tags with arbitrary names (these are
the user-chosen names of certain things to be described by that file. don't
blame me, I didn't design that file...), validation against an xml schema is
impossible/useless. therefore, my idea was to convert that file (replace the
arbitrary-name-tags by a new tag with a standard name and move the former,
arbitrary name to an attribute name=...) and then validate it. I'm using the
SAX API in Java. It would be nice to use the XMLFilter Interface to
transform the file, but how can I validate it AFTER it passed through the
filter class? re-convert it to an xml stream and parse it again, this time
using a validating parser? There must be some nicer solution...

Thanks,
Tobias Noebauer
 
N

Nigel Whitaker

Tobias Noebauer said:
...
It would be nice to use the XMLFilter Interface to
transform the file, but how can I validate it AFTER it passed through the
filter class? re-convert it to an xml stream and parse it again, this time
using a validating parser? There must be some nicer solution...

Hi Tobias,

One possibility is to use the JDK 1.5.0 beta (or "J2SE 5.0").

This provides the javax.xml.validation.Validator class.
The validate() method of which takes a Source argument;
if you use the SAXSource constructor you should be able
to feed the SAX stream from your XMLFilter straight into the
validator.

I thought there might have been a way of doing this with JDK 1.4.x
and Sun's MultiSchemaValidator (msv), but I cannot
see how after a quick look at it.

It may also be worth taking a look at sxpipe
at http://www.dev.java.net/

Nigel
 
D

Daniel Parker

Nigel Whitaker said:
I thought there might have been a way of doing this with JDK 1.4.x
and Sun's MultiSchemaValidator (msv), but I cannot
see how after a quick look at it.
It's easy. Create a Verifier from a Schema, get a VerifierFilter from the
Verifier, set the content handler on the VerifierFilter and set the parent
of the VerifierFilter to your XMLFilter.

Regards,
Daniel Parker
http://servingxml.sourceforge.net/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top