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?
condor888Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gurpsbassiCommented:
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.
0
condor888Author Commented:
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?
0
gurpsbassiCommented:
"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.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

condor888Author Commented:
@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?
0
gurpsbassiCommented:
use XML binding instead of just parsing it
This is not a good question.

They are two different things trying to achieve two different results.
If you want to simply parse your XML, visit each of the nodes e.t.c. then JAXP for parsing.

If you want to create an object model then JAXB. Which takes a XSD and creates a model from it.

After you have got a JAXB object you can do what you want with it. All depends on what persistence framework you have in place. Simply pick the attributes of the object you want to persist and map them to column names either using a framework or classic JDBC.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
condor888Author Commented:
Sorry about the confusion and thanks again for your patience.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.