Link to home
Start Free TrialLog in
Avatar of condor888
condor888

asked on

How to populate Java objects from XML given the xsd schema?

Given that I've already know a very complicated XML schema in xsd (such as https://github.com/mtconnect/schema/blob/master/MTConnectAssets_1.3_1.0.xsd) How can I create the appropriate Java classes to represent the data which I convert from XML files following that xsd?

What tools and techniques may I use to fulfil that requirement?

Should I create the Java classes to represent the data manually or is it possible to use some tool to generate those Java classes?
Avatar of gurpsbassi
gurpsbassi
Flag of United Kingdom of Great Britain and Northern Ireland image

If you're running with Java 6+ you can use xjc which is installed by default.
From this you can create a JAXB object model using the XSD.

Type xjc -help to see all the possible options.
Avatar of condor888
condor888

ASKER

That is a very helpful comments.

I saw different ways to parse XML using Java, such as JAXB, JAXP, DOM and SAX API. Would you please help me to compare those?
"Parsing" and "Binding" are two different things.


JAXP (Java API for XML Processing) This is the set of XML API's in Java used to parse an XML document using things like DOM and SAX.

JAXB (Java Architecture for XML Binding) is an API used to bind XML documents to a java object model.
@gurpsbassi thanks for your answer.
So when is the best scenario to use XML binding instead of just parsing it?

How can I persist the java object that we unmarshal from XML using relational database?
ASKER CERTIFIED SOLUTION
Avatar of gurpsbassi
gurpsbassi
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry about the confusion and thanks again for your patience.