Keith,
Hmm... So this will tell the SAX parser to use validation but I need some way to tell
the parser where the schema lives. All I have in my XML document is a namespace.
This is how I currently do it using a XMLReader.
XMLReader reader = XMLReaderFactory.createXMLReader();
reader.setFeature("http://xml.org/sax/features/validation", true);
reader.setFeature("http://apache.org/xml/features/validation/schema", true);
reader.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation",
"http://avaya.com/namespace"
+
getClass().getClassLoader().getResource("name-of-schema-file.xsd").toString());'
It appears the features can be configured via the castor.properties file. In fact it
looks like the first validation feature is added by default.
However, the setting of the property is the problem. This mapping of a namespace URI
to a schema location URI needs to happen at runtime. So I can't specify this in a
properties file. What I really need is a what to get a handle to the SAXParser /
XMLReader instance that will be used by the unmarshaller.
Something like:
SAXParser parser = unmarshaller.getParser();
XMLReader reader = parser.getXMLReader();
reader.setProperty(...); // same as above
then call
Object obj = unmarshaller.unmarshal(...)
Please let me know if I'm way off here but I can't figure out any other way to do it.
Thanks,
Tim
-----Original Message-----
From: Keith Visco [mailto:[EMAIL PROTECTED]
Sent: Tuesday, June 24, 2003 12:52 PM
To: [EMAIL PROTECTED]
Subject: Re: [castor-dev] Unmarshalling - XML schema validation
Hi Tim,
It should work properly. Try setting the parser validation property in
the castor.properties file.
--Keith
"Bardzil, Timothy J (Timothy)" wrote:
>
> I am attempting to unmarshall and XML document that is defined by an XML schema. I
> have chosen to use a mapping file rather than code generated directly from the
> schema for a number of reasons that I won't get into. However, I would like to use
> the schema for validation purposes when unmarshalling the document into objects. Is
> this possible?
>
> I can currently do this with a regular SAX parser by setting the
> http://apache.org/xml/properties/schema/external-schemaLocation property on the
> underlying XMLReader. I believe that Castor uses SAX so would something similar
> work?
>
> Thanks,
> Tim Bardzil
>
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
> unsubscribe castor-dev
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev