3

I asked this question before:

Generate XML from a class

I want to do this with Java.

Is it possible to do the same with Java via attributes?

or is there a framework i can use for this purpose as well.

1

3 Answers 3

8

XStream will allow you to represent any class as an XML. You can check here for an example.

Sign up to request clarification or add additional context in comments.

5 Comments

+1 Using XStream would be the simplest and easiest on this occassion.
One of the first dependencies I add to a new project. Even without any XML need: very useful for debugging !
Cool. That IS a really simple solution. I've never read about xstream until now.
@Jakrabbit: It is usually very simple and straightforward to use. If I am not mistaken XML generation can be controlled, to a certain extent, through the use of annotations.
@DarthVader - For a JAXB (JSR-222)/XStream comparison see: blog.bdoughan.com/2010/10/how-does-jaxb-compare-to-xstream.html. Note I'm the EclipseLink JAXB (MOXy) lead.
5

JAXB could be what you want. It's fairly common. You just add some annotations to your properties and any instance of that class can be serialized/deserialized to XML.

1 Comment

+1 for JAXB (JSR-222). JAXB implementations (Metro, MOXy, etc) do not require any annotations, they are only needed to customize the default XML representation: wiki.eclipse.org/EclipseLink/Examples/MOXy/GettingStarted/…
0

I prefer XStream, but there is also Castor XML

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.