Stephan:
Thanks for your help. I did get the Java objects to marshall without the
use of a mapping file.
I am now having problems with the unmarshalling of documents that use
elements that are of a group type. For instance I have defined in my
schema a description group as follows:
<xsd:group name="DescriptionGroup">
<xsd:sequence>
<xsd:element name="description"
type="xsd:string" minOccurs="0" maxOccurs="1"/>
</xsd:sequence>
</xsd:group>
This is used in my NodeType definition:
<xsd:complexType name="NodeType">
<xsd:sequence>
<xsd:group
ref="shr:DescriptionGroup"></xsd:group>
</xsd:sequence>
</xsd:complexType>
When in my instance document I have the description the unmarshalling
throws an exception.
<node>
<description> comment </description>
</node>
When I create the classes with the source generator I use the following
flags:
generateMappingFiles=true
createMarshalMethods=true
GenerateImportedSchemas=false
Validation=true
I am getting an error every time I try to use the description element in
a document. I have noticed that this happens with other group types.
Does group unmarshalling work?
Thanks,
Barbara
The error I get is as follows:
Error occurred in read. Target Exception is::
org.exolab.castor.xml.MarshalException : null
null{file: [not available]; line: 64; column: 18}
at
org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:669)
at
org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:563)
at
com.nortel.sce.xml.utils.XmlToJava.readXMLinstanceToObject(XmlToJava.jav
a:143)
at
com.nortel.sce.xml.utils.XmlUtils.unmarshallXML(XmlUtils.java:89)
at
com.nortel.sce.model.ContainerData.read(ContainerData.java:109)
at
com.nortel.sce.model.ContainerData.<init>(ContainerData.java:52)
at
com.nortel.sce.model.ApplicationData.getContainerByName(ApplicationData.
java:135)
at com.nortel.sce.model.ModelData.main(ModelData.java:273)
Caused by: java.lang.NullPointerException
at
org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalHandler.jav
a:1994)
at
org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalHandler.jav
a:1375)
at
org.apache.xerces.parsers.SAXParser.startElement(SAXParser.java:1376)
at
org.apache.xerces.validators.common.XMLValidator.callStartElement(XMLVal
idator.java:1214)
at
org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatc
h(XMLDocumentScanner.java:1171)
at
org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScan
ner.java:381)
at
org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1081)
at
org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:655)
-----Original Message-----
From: Stephen Bash [mailto:[EMAIL PROTECTED]
Sent: Friday, March 03, 2006 8:30 AM
To: [email protected]
Subject: Re: [castor-user] mapping and binding
Barbara-
I'm not much of an expert on the binding-file side, but I use mapping
files all the time. The short answer is no, you don't need both, but
yes, they both describe Java object <-> XML relations.
In general, I believe, the binding file is used to create Java code
(that can then be compiled and used in an application) from an XML
Schema. The binding file is most often (only?) used with the Castor
SourceGenerator, which creates Java classes that model an XML schema,
at which point Castor also creates extra classes (ClassDescriptors and
FieldDescriptors) that describe how the Java objects "map" to XML.
The mapping file provides an alternate method for the user to specify
how Java objects transform into XML content. I tend to think of this
as how one starts with a Java object model and then creates the XML
structure from it, but it is much more flexible than that.
Where the two methods somewhat meet is the
ClassDescriptor/FieldDescriptor level. When a user loads a mapping,
Castor reads the mapping file and internally creates the appropriate
descriptors. If the SourceGenerator was used, the descriptors exist
as compiled classes and are instantiated as they are needed (thus the
mapping file usually isn't required).
That might be more information than you needed, but hopefully it
answers the question. Let us know if you have further questions.
Stephen
On 3/3/06, Barbara Prechtl <[EMAIL PROTECTED]> wrote:
>
>
>
> To whom it may concern:
>
>
>
> I was wondering what the difference between a mapping file and a
binding
> file is.
>
>
>
> Is this correct:
>
>
>
> A mapping file is used for writing java objects to xml.
>
> A binding file is used to read xml to java objects.
>
>
>
> They both seem to describe the element to object relation. Are both
needed?
>
>
>
> Thanks,
>
> Barbara
-------------------------------------------------
If you wish to unsubscribe from this list, please
send an empty message to the following address:
[EMAIL PROTECTED]
-------------------------------------------------