Thanks. I understand how those Marshaller methods work - it is a nice
API.
But, I'm still looking for a way to pass around an Xml Object - and by
this I mean anything that could hold an XML infoset - could be a DOM,
JAXBElement, a JAXB "value class", a Stream, etc.
Maybe I could use javax.xml.transform.Source ??
-- Mark
Kohsuke Kawaguchi wrote:
>
> Here's how you do it. Since JAXB has to support POJOs, it's difficult to
> defint those as methods on objects. So they are defined on Marshaller.
>
> Mark Hansen wrote:
>
>> newDomNode() - to get an instance of the XML as a DOM
>
>
> DOMResult dr = new DOMResult();
> marshaller.marshal( object, dr );
> dr.getNode()
>
>> newInputStream() - to get it as a stream
>
>
> ByteArrayOutputStream baos = new ByteArrayOutputStream();
> marshaller.marshal( object, baos );
> new ByteArrayInputStream(baos.toByteArray());
>
> (On this one, XMLBeans implement it better, as it doesn't have to buffer
> things)
>
>> xmlText() - to get it as a String
>
>
> StringWriter sw = new StringWriter();
> marshaller.marshal( object, sw );
> sw.toString();
>
>> save(ContentHandler ch, LexicalHandler hl) - to run the instance
>> through SAX handlers
>
>
> SAXResult sr = new SAXResult(...);
> marshaller.marshal( object, sr );
>
>