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

Reply via email to