Java and XML Schema help

zolf
zolf used Ask the Experts™
on
Hello there,

I have been provided with 2 XML Schema file and told to provide my data in XML format. Now I want to know using Java how can I acheive this. I have my data in the database.Can somebody please guide me to the right path and hence acheive my goal. I have attached one of the XML schema file.

cheers
Zulf
Order.xsd
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Usually the way people approach this is to use a tool, like JAXB to build a set of Java classes.

Then you read the data from the database, build up a set of objects (using the generated Java classes) and then you "marshall" (convert) those objects into the target XML.

If you use this sort of approach, you don't need to write the Java classes by hand yourself or write the code to generate the XML - the tool does it all for you.

That being said, if you've never used a tool like this, you need to learn first how to use it.
Fortunately there is a tutorial here:
https://docs.oracle.com/javase/tutorial/jaxb/intro/examples.html

I would suggest going through that whole tutorial first- download and run the examples etc. so you fully grasp what is going on.  Then you can try with your XSD files and follow the same steps.

I'm afraid I can't personally help you with doing that as I've never actually had the pleasure of having to dump out XML like this - but there's plenty of other experts who have - in case you get stuck.

Hope that helps,

Doug

Author

Commented:
dpearson,

Thanks for your feedback. That was helpful. I tried using the jxc tool to generate the java class from the xsd schema file. BUt for some reason I get this error. Could it be that java cannot convert complex xsd files. Any suggestion??

parsing a schema...
undefined simple type 'NCString '
  line 14 of file:/C:/dev/workspace/ZDemo2D/resource/Order.xsd

undefined simple type 'NCString '
  line 15 of file:/C:/dev/workspace/ZDemo2D/resource/Order.xsd

Failed to parse a schema.
Hmm - as I say I'm not really familiar with JAXB itself and its errors.  That sounds like a base type is just missing.

If it was me, I'd try editing down the XSD until you get a simple version that works and then try adding things back in to determine where it breaks.

Sorry I can't be more help,

Doug

Author

Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for zolf's comment #a41546068

for the following reason:

thanks!!

Author

Commented:
cheers!!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial