Thomas Jones-Low wrote:
Jean-Christophe Garnier wrote:
Hello,
I wish to obtain a DOM or string representation of an object marshaling. Currently I have seen only explanations to generate a file.
Is this possible without generate a file ?
Thanks by advance,
Use a java.io.StringReader or java.io.StringWriter class as your IO class. For example:
public void write ()
{
try
{
IBindingFactory bfact = BindingDirectory.getFactory(<Base Class>.class);
IMarshallingContext mctx = bfact.createMarshallingContext();
mctx.setIndent(4);
StringWriter outputString = new StringWriter();
mctx.marshalDocument(data, "UTF-8", null, outputString);
}
catch (Exception ex) { ex.printStackTrace(); }
}
public void read(String inputString)
{
try
{
IBindingFactory bfact = BindingDirectory.getFactory(<Base Class>.class);
IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
StringReader readString = new StringReader (inputString);
data = (<Class>) uctx.unmarshalDocument (readString, null);
}
catch (Exception ex) {ex.printStackTrace(); }
}
I'll add this to the wiki.
Thomas' response is correct, and thanks for volunteering to add it to the wiki. I'll add that if someone wants to do this more efficiently they'd just need to implement an org.jibx.runtime.IXMLWriter that outputs to DOM (or SAX event stream, or whatever). This shouldn't be too difficult to do, and would give considerably better performance than outputting to a string that then gets parsed.
- Dennis
-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com
_______________________________________________
jibx-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jibx-users
