users@jaxb.java.net

Re: How to transform Element to String [WAS: Re: How to use anytype: get and set value in pojo]

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Wed, 20 Feb 2008 09:11:13 +0100

Hi.

> just reposting the second part of my issue:
>
> XJC generates an @XmlAnyElement Element, which is what I want. Now I'm
> left with the question, what's the best way to read the element to s.th.
> I could store in the database (e.g. a string), and how to recreate an
> Element from e.g. a string.
>
> Is it good (in terms of performance, simplicity) to do this by using
> Transformer, DOMSource and StringWrite/StreamResult like this:
>
> final DOMSource source = new DOMSource( any );
> final Transformer transformer =
> TransformerFactory.newInstance().newTransformer();
> final StringWriter stringWriter = new StringWriter();
> final StreamResult result = new StreamResult( stringWriter );
> transformer.transform( source, result );
>
> Or is there an easier way?

This is what I usually do.

Bye.
/lexi
ps. Are you aware of https://hyperjaxb3.dev.java.net?