Hello: I have what I think is a straightforward operation I don't know how to accomplish in JiBX - I want to marshall several different objects into a single document, but the objects may have different marshalling contexts.
For example, the code (where 'out' is an OutputStream) IBindingFactory bFact = BindingDirectory.getFactory( object.getClass() ); IMarshallingContext mCtx = bFact.createMarshallingContext(); mCtx.setIndent( 4 ); mCtx.marshalDocument( object, "UTF-8", null, out ); works fine if the document file will contain only the object rooted at 'object'; but if I have several such objects, where the call to 'getFactory' might return a different factory, I gather I have to do something like this to build a document (with Object[] roots ): 1 // manually construct the XML declaration 2 out.write( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".getBytes() ); 3 4 // loop thru all objects 5 for ( int i = 0; i < roots.length; i++ ) { 6 IBindingFactory bFact = BindingDirectory.getFactory( roots[i].getClass() ); 7 IMarshallingContext mCtx = bFact.createMarshallingContext(); 8 mCtx.setIndent( 4 ); 9 mCtx.setOutput( out, "UTF-8" ); 10 11 if ( i < roots.length - 1 ) { 12 // this invocation won't call 'endDocument', so I can add other objects 13 IMarshaller mr = mCtx.getMarshaller( index, roots[i].getClass().getName() ); 14 mr.marshal( object, mCtx ); 15 } 16 else { 17 // this final invocation will call 'endDocument' and properly close file 18 mCtx.marshallDocument( roots[i] ); 19 } 20 } The problem is in line 13: I don't know how to get the correct value for 'index'. The JavaDoc says 'class index for marshalling definition' but I have no idea what that means, much less how to obtain it programmatically. I searched in vain for sample code that works like this. Any help much appreciated, either in explaining this API, or even an alternate approach that skins the cat another way... Thanks a lot, Richard Rodgers ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ jibx-users mailing list jibx-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jibx-users