Hi
daab wrote:
> Hi,
>
> I'm relatively new to xml, marshaling/unmarshaling, castor, and this forum.
> I've gone through
> http://www.ibm.com/developerworks/xml/library/x-xjavacastor3/ this tutorial
> .
>
> I need to marshal a large hashtable of a custom java object onto an XML
> file. This XML file must conform to an existing XSD file. The object's
> class will be modified to conform to castor API (for set, get functions),
> but I want to keep changes to a minimum.
>
> I'll later need to unmarshal from the XML file to a collection of my
> objects, for maintenance. I know castor has its own mapping file that needs
> to be created manually.
Yes, if you have existing Java classes and want to use them for XML data
binding (aka unmarshalling from XML and marshalling to XML business).
> So what I need help with is, how should I go about creating the mapping
> file?
Use an XML editor, and add class and field mappings as needed.
> Do I need to create the mapping file by looking at the XSD, manually?
Yes and no. It would be simpler to look at an XML document instance that
conforms to that XML schema, and define your mappings according to this.
> Is there a way to automate this?
There's the MappingTool, but I believe that you won't be able to use it
for your business (due to the Maps).
> Is there another approach to my scenario? I know I can also create classes
> (or class descriptors [is that the same thing?]) from XSD files using the
> sourceCodeGen (sp?) tool.
Yes.
> However, I want to try to avoid this approach (of
> using a generated class as it would be an unnecessarily larger class).
Larger in what sens, if I may ask ?
> I'll use it if theres no other way.
There's more than one option, and it's your choice. Personally, I'd use
code generation and avoid having to write a (potentially biggish)
mapping file(s), but as already said, that#s my preference.
> class descriptors [is that the same thing?])
No, it's not. When you use the XML code generator to create java sources
from an XML schema, you'll get two sets of classes.
a) entity classes (Java representations of your e.g. <complexType>
definitions)
b) Castor-specific descriptor classes (one for each entity class).
What is a descriptor class ? Let me explain it like this: if you start
with existing Java classes, and you write a mapping file (manually),
Castor will - at start-up time - analyze the mapping file provided and
(internally) convert these classes to descriptor classes.
I hope this explains things a bit more.
Regards
Werner
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email