-1

Possible Duplicate:
What is the best way to convert a java object to xml with open source apis

I found existing questions 1 and 2 on the subject, but I wasn't sure if it was up-to-date, and the best fit for what I'm trying to do.

I've had one strong suggestion of XMLBeans, but there isn't too much discussion on it here on SO, and it's not even mentioned on the first link above (not with any upvotes, anyway).

Is JAXB still the best recommendation for this? If so, are there any simple tutorials that walkthrough A->B with object->xml?

Update: I'm being given Lists of java objects, and need to convert them to xml following a given schema.

4
  • So, you have no influence over both input and output, you're just the man in the middle? Commented May 7, 2012 at 14:47
  • That is a correct assumption. Commented May 7, 2012 at 14:48
  • 1
    To map an existing object model to an existing XML schema you can take advantage of MOXy's XPath based mapping. Here is an example of mapping one object model to both the Google and Yahoo weather services: blog.bdoughan.com/2011/09/…. Note: I'm the EclipseLink JAXB (MOXy) lead. Commented May 9, 2012 at 9:48
  • Hi Blaise, thanks for the reply. I'm quite new to xml/object serialization, as I'm sure you can tell from the initial question. Your blog and example look very interesting, though I'm confused trying to follow the weather apis. Do you have any basic starter examples for using JAXB with MOXy? Commented May 9, 2012 at 14:55

2 Answers 2

4

I prefer to use JAXB that supports both annotation and XML based mapping.

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

1 Comment

AlexR given that my answer and yours diverge quite a bit, it seems that this is a highly subjective topic. Do you agree?
3

I'd go with XStream, as your question 2 suggests.

It needs no annotations, just configuration, and can serialize simple objects out of the box. To make the objects fit a given schema, you'd convert them to objects that closely resemble the schema first and serialize those to XML.

The XStream page also holds the tutorials you request.

3 Comments

I tried playing around with XStream, can't get anything to compile even with the xstream-1.4.2.jar in my path. It can't find XStream..
What download did you use? If you manage your dependencies manually (not via Maven, Gradle...), did you check to add all the dependencies XStream requires?
I just grabbed the binary distro off the main page.. I got it to recognize XStream finally, although I'm having the same issue again with other functions. Importing com.thoughtworks.* didn't work, had to directly import .xstream as well...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.