Chris is correct, but perhaps states things too strongly. If you have several types of objects that can be the root element of your document you can define <mapping>s for each in a single binding definition. The unmarshaller will automatically return the proper type of object matching your input document. The class you supply in the BindingDirectory.getFactory() call can be *any* class that has a top-level <mapping> definition in the binding.

You can also do tricks at runtime to select between several possible bindings, as described at http://jibx.sourceforge.net/tutorial/binding-custom.html#frontend , but that's really only needed in cases where you have several versions of the same documents (as in versioned schemas).

 - Dennis

Chris Hill wrote:

I don't think JiBX's functionality extends to finding out what the root element is. This kind of thing is already handled well by apis such as SAX, DOM, or XMLPull. JiBX is a marshaller/unmarshaller and its really fast and great at what it does. But if you want to find out the root element of an object, you have a vast, huge, extensive number of ways to do it using XML APIs, and after that use JiBX to (un)marshal.

Peace
C


Pascal Dimassimo wrote:

I notice from the usage documentation on the jibx site that in order to unmarshall a xml document into a object, I need to know in advance what the type of the object is:

IBindingFactory bfact =
        BindingDirectory.getFactory(Customer.class);
IUnmarshallingContext uctx =
        bfact.createUnmarshallingContext();
Object obj = uctx.unmarshalDocument(
        new FileInputStream("filename.xml"), null);


What if I don't know that "filename.xml" is actually holding a Customer object? Is there a way to make jibx look in the mapping automatically to find which object the root element of "filename.xml" is refering to?


Thanks



-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE
LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
_______________________________________________
jibx-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to