• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

How to generate xml files from xsd?

 
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

I'm really new to XSD and XML (I know the basic XML such as elements and tags). I have an XSD files and I need to set the data on some of its elements and (some have list type) then convert it to XML file.

Can someone please give me an idea or overview on how can I do it? and what tools do I have to use?

Thanks!
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In eclipse you can generate the xml. Right click the XSD and use option to Generate the XML.
 
Bartender
Posts: 322
24
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Winston,

Just to make sure we are on the same page, a XSD is a schema file defining the attributes and elements of a XML entity within an XML file (usually a file, but could be a stream, etc...). So, you don't really set elements in the XSD.

If you want to create XML entities from the XSD using Java, Java offers two robust APIs for working with XSD/XML file formats. The older JAXP, and the newer (more efficient) JAXB - Java Architecture for XML Binding. Assuming you are running Java SE 6 or greater, JAXB should be included. If you are using a legacy system, check out the CodeRanch XML FAQ for more information on JAXP.

Included with JAXB is a command line utility called xjc. That's where you will want to begin. xjc will convert a XSD into corresponding JAXB annotated Java classes. For more information, please review: https://jaxb.java.net/2.2.4/docs/xjc.html

Once you have the JAXB annotated Java classes, you'll need to look at creating XML output through a process called marshalling. As XML is often used in Web Services, Oracle has included instructions on JAXB as part of their Java EE guides. You can learn more about implementing JAXB here: https://docs.oracle.com/javaee/7/tutorial/jaxrs-advanced007.htm#GKKNJ


 
Winston Liek
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys, thanks for your response.

I'm really not sure how to process it...

I have given an XSD file by my boss and a table in the database (that is changing, thousands of rows). I was given a task to create a java method that will generate an xml file using the values on the database upon invoking the said method.

I'm really not sure what to do to the XSD file and how to generate the XML out of XSD (setting the values from the database to the XML elements).

 
Saloon Keeper
Posts: 7100
165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
More useful than the XSD file would be an example XML file - XSDs generally describe an unlimited number of different XML files, so from that alone it is not possible to create an XML file.
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Moores wrote:More useful than the XSD file would be an example XML file - XSDs generally describe an unlimited number of different XML files, so from that alone it is not possible to create an XML file.



Depends how complex the XSD is.
Or, more like it, is how flexible it is.

Most of the ones I've dealt with have been fairly tightly written, so figuring out the format of a valid XML file for it wouldn't be too much of an issue.

Something like the more obscure parts of OTA (the travel standard)? Possibly not so easy.
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
starting from xsd, can you please guide me or tell me what plugin to install/what to do to generate the XML?
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic