Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2007

Tip: Looking for answers? Try searching our database.

Java objects from XSD?

Thread view: 
Wojtas - 19 Sep 2007 09:33 GMT
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
Steve W. Jackson - 19 Sep 2007 15:41 GMT
> Hi!
>
[quoted text clipped - 6 lines]
>
> 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.
Signature

Steve W. Jackson
Montgomery, Alabama

Roedy Green - 19 Sep 2007 17:11 GMT
On Wed, 19 Sep 2007 10:33:35 +0200, "Wojtas"
<wkrugiolka@poczta.onet.pl> wrote, quoted or indirectly quoted someone
who said :

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

See http://mindprod.com/jgloss/parser.html

Look for a Java parser. Then prune it to ignore anything you don't
want.
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Stefan Ram - 19 Sep 2007 17:20 GMT
>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(); }}
Manish Pandit - 19 Sep 2007 18:11 GMT
> Hi!
>
[quoted text clipped - 6 lines]
>
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.