Arash
Arash

Reputation: 12465

multiple XML digestion in Java

I am looking for a easy to implement xml to java binding. The problem I am facing that there is more than one xml file, and I need to create one object tree from these files. JAXB is not helping for two reason : the xmls are not usually have any schema, and second JAXB does not offer any solution for combining them. I tried smooks too, but it also doesn't offer any multiple XML digestion system. Does anybody have any idea?

Upvotes: 2

Views: 381

Answers (3)

Kristian
Kristian

Reputation: 6623

I've used XMLBeans before. Really easy and flexible to use, should be able to help you a great deal.

Upvotes: 0

bdoughan
bdoughan

Reputation: 149037

You can do this in JAXB using an initialized XmlAdapter. Below is a link to answer I gave to a similar question:

Note:

JAXB implementations (Metro, EclipseLink MOXy, Apache JaxMe) do not require an XML schema:

Upvotes: 3

brabster
brabster

Reputation: 43580

If you use JAXB, I suggest creating your own XSDs for the XML files your need to use. That'll help you document what you thought the schema was at the time, and help identify any future issues due to change at the source.

Then, create a class or classes that deserialize the individual documents into the JAXB-generated classes and then build the object you want from those objects.

Even if you don't use JAXB, I'd still recommend using this kind of pattern to isolate the transformation from XML to Java and keep the part of your app that knows about XML in one place, away from your business logic.

Upvotes: 0

Related Questions