SAX: perform valisation after passing through filter?

Discussion in 'XML' started by Tobias Noebauer, Sep 10, 2004.

  1. 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
     
    Tobias Noebauer, Sep 10, 2004
    #1
    1. Advertising

  2. "Tobias Noebauer" <> writes:

    > ...
    > 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
     
    Nigel Whitaker, Sep 10, 2004
    #2
    1. Advertising

  3. "Nigel Whitaker" <> wrote in message
    news:...
    > "Tobias Noebauer" <> writes:
    >
    > > ...
    > > 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...

    >
    >
    > 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/
     
    Daniel Parker, Sep 19, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    789
    Wilco Bauwer
    Feb 16, 2005
  2. JKop
    Replies:
    3
    Views:
    336
    John Harrison
    Nov 2, 2004
  3. Tim Rowe

    Passing data out of a Sax parser

    Tim Rowe, Sep 20, 2003, in forum: Python
    Replies:
    6
    Views:
    296
    Andrew Dalke
    Sep 23, 2003
  4. zax75
    Replies:
    1
    Views:
    1,135
  5. Replies:
    10
    Views:
    520
Loading...

Share This Page