Keith, thanks a lot for the information on the FieldHandlerFactory. I haven't implemented this, but that sounds like a much better solution to my needs.
I have an additional question about the Vector approach. If you are using a Vector, the type must be specified as java.lang.Object. So, if you add many different types of objects (that are all mapped) to a Vector and tell Castor to marshal the Vector, will Castor always use the xsi:type? Shouldn't Castor be able to resolve their classname using reflection and find the appropriate mapping (e.g. use the correct xml-bound name, etc.)? When I experimented with this, Castor output an xsi:type attribute for every object and named every object the same thing (e.g. "container"), which is unacceptable in my case. Thanks! On Wed, 28 Jan 2004 12:51:52 -0600, "Keith Visco" <[EMAIL PROTECTED]> said: > > > 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 > -- Jeremy Haile [EMAIL PROTECTED] ----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to [EMAIL PROTECTED] with a subject of: unsubscribe castor-dev