Nadav-

You can have Castor do validation while it is parsing the file into
Java objects.  There's a how-to document online:

  http://castor.org/how-to-enable-xml-validation.html

Unfortunately in my experience the validation exceptions aren't
particularly easy to read either, so I would suggest catching the
validation exception and attempting to get the useful information out
of them before printing/throwing a useful error message.

HTH,
Stephen


On 11/13/06, nadav steindler <[EMAIL PROTECTED]> wrote:
Hi James, thanks for the quick response.

So I have a W3C schema defined for the file.

Theoretically, I could just tell the systems engineer to validate the file
with XMLSpy, however the requirements for this project are that the
validation needs to be done by the java servlet I'm writing and that my
program needs to do the validation and print out clear error messages if the
xml file has problems.  Are there any java libraries that do this?

Nadav


On 11/13/06, James Abley <[EMAIL PROTECTED]> wrote:
> Validate the XML first, using DTD, RELAX NG, W3C Schema or similar?
>
> James
>
> nadav steindler wrote:
> >
> > How do I parse an xml file and build a parse tree of caster-generated
> > objects and get it to produce error messages a systems engineer can
> > understand(short, with line numbers, with no reference to internals of
> > the code such as classes), rather than:
> >
> >  "The following exception occured while validating field: _firstVersion
> > of class:
com.nds.castorgenericformat.AMSGenericConversionFormat: The
> > following exception occured while validating field:
> > _firstVersionDefTypeHeader of class:
> > com.nds.castorgenericformat.FirstVersion : The
following exception
> > occured while validating field: _headerTypeInput of class:
> > com.nds.castorgenericformat.FirstVersionDefTypeHeader:
The following
> > exception occured while validating field:
> > _groupOfSTBMessageFieldDefsList of class:
> > com.nds.castorgenericformat.HeaderTypeInput: The
following exception
> > occured while validating field: _flagsByte of class:
> > com.nds.castorgenericformat.GroupOfSTBMessageFieldDefs
: The field
> > '_name' (whose xml name is 'name') is a required field of class
> > 'com.nds.castorgenericformat.FlagsByte"
> >
> >
> > Which is what happens when I do:
> >
> >         try
> >         {
> >             //Set up a Unmarshaller
> >             Unmarshaller unmarshaller = new
> > Unmarshaller(AMSGenericConversionFormat.class);
> >
> >             //    Build parse tree from file
> >             AMSGenericConversionFormat genericFormat =
> >
(AMSGenericConversionFormat)unmarshaller.unmarshal(reader);
> >
> >         }
> >         catch (MarshalException e1)
> >         {
> >             system.out.println(e1.getMessage());
> >         }
> >         catch (ValidationException e2)
> >         {
> >             system.out.println(e2.getMessage());
> >         }
> >
> >
> >
> >
> > I'd rather get something like:
> >
> > "error line 52 in foo.xml, attribute "name" is missing"
> >
> >
> >
> >
> > Thanks,
> >
> > Nadav
>
>
>
---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>



---------------------------------------------------------------------
To unsubscribe from this list please visit:

   http://xircles.codehaus.org/manage_email

Reply via email to