I did some more digging and was able to get Castor to load my file. I
had to do my unmarshalling this way though:
FileReader reader;
ObjectModel om = null;
reader = new FileReader(".\\xml\\rpr2-d18.xml");
Unmarshaller um = new Unmarshaller(ObjectModel.class);
um.setValidation(false);
om = (ObjectModel)um.unmarshal(reader);
That worked fine, or at least didn't fail with an exception; I still
haven't tried to actually work with the unmarshalled data, but a quick
examination of om in the debugger looked ok.
It looks like my root problem is that the _validate member of the
unmarshaller was set to "true" with the method I used to read my
ObjectModel out of the file. I'm not sure why validation being on
caused the problem though; the file is a valid XML document that
conforms to the schema I used to generate the code.
-Allan
-----Original Message-----
From: Gillis, Allan [mailto:[email protected]]
Sent: April-22-09 11:44 AM
To: [email protected]
Subject: [castor-user] Error during unmarshall
Hi all,
I've generated code using Castor to read my xml files. The code
generation part went fine, and all the code compiles and so on.
Unfortunately when I try to unmarshal data from the file I get:
org.exolab.castor.xml.MarshalException: The following exception occured
while validating field: _objects of class:
ca.gc.drdc_rddc.atlantic.mc2cd.fomreader2.ObjectModel: The following
exception occured while validating field: _objectClassList of class:
ca.gc.drdc_rddc.atlantic.mc2cd.fomreader2.Objects: The following
exception occured while validating field: _attributeList of class:
ca.gc.drdc_rddc.atlantic.mc2cd.fomreader2.ObjectClass: The following
exception occured while validating field: _name of class:
ca.gc.drdc_rddc.atlantic.mc2cd.fomreader2.Attribute:
HLAprivilegeToDeleteObjectdoes not match the required regular
expression: "[\w-._:]+"{File: [not available]; line: 4823; column: 15}
Now, I should tell you that the structure of my XML files is that there
is a top level element called "ObjectModel" that contains lots of other
elements. What I tried to do that generated that error is this (I've
omitted the try-catch for clarity):
FileReader reader;
ObjectModel om = null;
reader = new FileReader(".\\xml\\rpr2-d18.xml");
om = ObjectModel.unmarshal(reader);
I did download the Castor source and I stepped through to find the line
that causes the problem. It exception seems to be thrown in line 748 of
org.castor.xml.Unmarshaller which is:
parser.parse(source);
When I examine the value of "source" I see that it is an instance of:
org.xml.sax.InputSource
While parser is an instance of:
com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl
I did some playing around with my xml file and found that the problem
seems to centre around one particular XML element in my files, for the
error message I've attached it's this one:
<attribute name="HLAprivilegeToDeleteObject"/>
This particular instance of <attribute/> is always the first one in any
of my files. I tried removing it just to see what would happen, and the
same error is generated on the next one in the file, i.e. the first one
the parser encounters.
So, any idea what I can do to fix this? Altering my schema is NOT an
option as it's part of an IEEE standard and I must be able to use it.
-Allan
---------------------------------------------------------------------
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