Jeremy Haile wrote:
>
> My marshalling/unmarshalling business needs require a flexible way to
> marshall and unmarshall large amounts of objects to arbitrary files. I
> am currently using Marshaller.setMarshallAsDocument(false) to output
> multiple objects to files deteremined by our business logic. These files
> then need to be human editable and unmarshalled back into our
> application.
>
> However, to my knowledge there is no way for Castor to import many
> objects from one file. Currently I am dynamically generating a source
> file at build time that "wraps" all of the XML files that have been
> marshalled by Castor. I do this to create one root element so that the
> XML parser doesn't yell at me. QUESTION #1: Is there an easier way to
> unmarshall many objects from one file or multiple files?
The parser expects a well formed XML file. So you must have a
well-formed XML file if you want to unmarshal it in Castor. The most
common solution is to wrap everything in a root element and then strip
off this root element during unmarshalling by using your own
ContentHandler and then forwarding all other events on to the
UnmarshalHandler.
However, you could also pass in a Vector as the root object, as long as
you have a good enough mapping file so that Castor can correctly find
all child elements based on element name.
>
> Also, I would like the xmlns:xsi mapping to be present ONLY in the root
> element, whereas currently Castor places the xmlns:xsi attribute in every
> element that requires an xsi:type attribute.
Just set this at the start of marshalling:
marshaller.setNamespaceMapping("xsi",
"http://www.w3.org/2001/XMLSchema-instance");
> QUESTION #2: Is there any
> way for me to leave the xsi:type attributes, but not output the xmlns:xsi
> attribute? Since I will have an xmlns:xsi attribute in my root element,
> I have no need to repeat the namespace mapping throughout my document.
Use the above.
--Keith
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev