views:

237

answers:

1

Is there something akin to the .NET xsd.exe for java - generating classes from a schema that you can easily de-serialize ? - or , What's the common practice for parsing and pull out/validate the content xml documents in Java ?

Traversing a DOM tree and littering code with XPath queries to get the data you need seems quiet messy.

+5  A: 

What you're after a data binding framework for XML. The popular ones are JAXB, JiBX and XmlBeans. They all allow you to take an XML schema and generate a bunch of java classes, and also have a runtime component which serializes/deserializes to and from XML and objects.

No one of them is the clear winner, they each have their strengths. JAXB is now included as part of Java 6, so that'd be my default choice.

skaffman
XStream is pretty good, except for its lack of namespace support.
duffymo
Correct me if I'm wrong, but XStream has no code generation ability, it's just for lightweight object-to-XML streaming.
skaffman