How to programatically assign a validating schema using Xerces?

Discussion in 'XML' started by Duncan Smith, Dec 12, 2003.

  1. Duncan Smith

    Duncan Smith Guest

    Hello All,

    Has anyone found a way to specify an xsd schema programatically when
    using the apache xerces xml processor? I know that the validation
    works fine as long as the xml instance document explicitly refernces
    the schema via an 'xsd:xsi schemaLocation=...' tab. But how can you
    validate xml documents which don't contain the schemaLocation?

    Reading the instance and assigning the schemaLocation before flushing
    it back out and reading it back works, but is such bad practice and
    wasteful that it's not really worth considering.

    MSXML has a simple validateOnParse and Schema Location properties
    which can be set when parsing an instance. I was hoping there would
    something similar in Xerces?

    Thanks for any furher info..

    Duncan
    Duncan Smith, Dec 12, 2003
    #1
    1. Advertising

  2. > Has anyone found a way to specify an xsd schema programatically when
    > using the apache xerces xml processor?
    >

    You have to call these methods on the parser object:
    setFeature("http://xml.org/sax/features/validation", true);
    setFeature("http://apache.org/xml/features/validation/schema"
    setProperty("http://apache.org/xml/properties/schema/external
    -schemaLocation", "<namespace> <schema file>");

    Jesper

    --
    Jesper Zedlitz eMail :
    Homepage : http://www.zedlitz.de
    ICQ# : 23890711
    PGP-Key : http://zedlitz.de/pub_key.asc
    Jesper Zedlitz, Dec 15, 2003
    #2
    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. Helen
    Replies:
    0
    Views:
    810
    Helen
    Mar 2, 2004
  2. Jasmin Wason
    Replies:
    0
    Views:
    485
    Jasmin Wason
    Aug 1, 2003
  3. bugbear
    Replies:
    0
    Views:
    1,000
    bugbear
    Aug 28, 2003
  4. Yona
    Replies:
    0
    Views:
    541
  5. Kevin Partin
    Replies:
    1
    Views:
    1,361
    Martin Honnen
    Feb 13, 2004
Loading...

Share This Page