Thanks Stephen,  I'll take a look at that and let you know what happens.

Thanks!
- Matt

On 4/20/06, Stephen Bash < [EMAIL PROTECTED]> wrote:
Matt-

Validation during unmarshalling takes place in the parser itself, so
it's really a question of how you get the parser to find the schema.
I traditionally have used the schemaLocation attribute in the root of
the XML document, but there are ways to programmatically set the
schema location for JAXP compliant parsers.  I just did a google
search for jaxp validating xml and it appears the documentation has
changed since I looked at it, but the process I followed is (I've done
this part several times):

1) Get a reference to a SAX parser factory
2) Turn on validation and namespace awareness in the factory
3) Set the following attributes:
         http://java.sun.com/xml/jaxp/properties/schemaLanguage
         http://java.sun.com/xml/jaxp/properties/schemaSource
   (The first is usually http://www.w3.org/2001/XMLSchema , the second
points to your schema file)
4) Use the factory to obtain a parser object

Now the Castor part (which I haven't done):

5) Instantiate an Unmarshaller object
6) Load any mappings needed
7) Call createHandler on the Unmarshaller object to get an UnmarshalHandler
8) Set the parser's contentHandler and errorHandler using the UnmarshalHandler
9) Parse the document
10) Call getObject on the UnmarshalHandler to obtain the root of the
object model

HTH,
Stephen

On 4/20/06, Matt Secoske <[EMAIL PROTECTED]> wrote:
> Hello Everyone,
>
> I am trying to do schema validation on an XML file during unmarshalling, and
> am somewhat confused as to how I can set the XSD.  I've been through the
> how-to, which shows how to do it with Marshalling, but the handy-dandy "
> setSchemaLocation" method does not appear to exist  for the Unmarshaller.
>
> Any thoughts on how I can do that?
> Thanks!
> --
> Matt Secoske
> http://blog.secosoft.net



--
Matt Secoske
http://blog.secosoft.net

Reply via email to