Java objects from XSD?

W

Wojtas

Hi!

How can i generate java domain objects that represents XSD elements?
I have tested jaxb and it generates too many things (annotations, statci
classes inside, enums etcetera).

I just need to generate classes with fields, getters and setter.
Is there some tool that can do this?


Pozdro, Wojtas
 
S

Steve W. Jackson

"Wojtas said:
Hi!

How can i generate java domain objects that represents XSD elements?
I have tested jaxb and it generates too many things (annotations, statci
classes inside, enums etcetera).

I just need to generate classes with fields, getters and setter.
Is there some tool that can do this?


Pozdro, Wojtas

Sounds like <http://xmlbeans.apache.org/> might have a solution you can
use. You provide the schema (XSD) file, and it creates Java classes
around it.
 
S

Stefan Ram

Wojtas said:
I just need to generate classes with fields, getters and setter.

public class Main
{ public static void main( final java.lang.String[] args )
throws java.lang.Throwable
{
final java.lang.String nl = "\n";
final String path = "Example.java";
final String encoding = "UTF-8";

new java.io_OutputStreamWriter
( new java.io.FileOutputStream( path ), encoding ).append
( "class Example" + nl +
"{ private int field;" + nl +
" public int getField(){ return field; }" + nl +
" public void setField( final int field )" + nl +
" { this.field = field; }}" + nl ).close(); }}
 
M

Manish Pandit

Hi!

How can i generate java domain objects that represents XSD elements?
I have tested jaxb and it generates too many things (annotations, statci
classes inside, enums etcetera).

I just need to generate classes with fields, getters and setter.
Is there some tool that can do this?

Pozdro, Wojtas

XMLBeans, as pointed out by Steve is the best option. You will see
enums if the XSD contains <xsd:enumeration>. What gets generated is a
reflection of the model defined in the XSD. Of course there is no way
to enforce rules like minOccurs, maxOccurs and similar constraints.

-cheers,
Manish
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top