Java objects from XSD?

Discussion in 'Java' started by Wojtas, Sep 19, 2007.

  1. Wojtas

    Wojtas Guest

    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
    Wojtas, Sep 19, 2007
    #1
    1. Advertising

  2. In article <fcqn1v$8tk$>,
    "Wojtas" <> wrote:

    > 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.
    --
    Steve W. Jackson
    Montgomery, Alabama
    Steve W. Jackson, Sep 19, 2007
    #2
    1. Advertising

  3. Wojtas

    Roedy Green Guest

    On Wed, 19 Sep 2007 10:33:35 +0200, "Wojtas"
    <> 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.
    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
    Roedy Green, Sep 19, 2007
    #3
  4. Wojtas

    Stefan Ram Guest

    "Wojtas" <> writes:
    >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(); }}
    Stefan Ram, Sep 19, 2007
    #4
  5. On Sep 19, 1:33 am, "Wojtas" <> wrote:
    > 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
    Manish Pandit, Sep 19, 2007
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Markus
    Replies:
    1
    Views:
    1,081
    Markus
    Nov 22, 2005
  2. Rick Razzano

    XSD document for XSD defintion

    Rick Razzano, Sep 26, 2003, in forum: XML
    Replies:
    1
    Views:
    470
    C. M. Sperberg-McQueen
    Sep 26, 2003
  3. Replies:
    1
    Views:
    848
    Martin Honnen
    Jan 14, 2004
  4. Peter Aberline

    xsd:any as a child of xsd:all

    Peter Aberline, Apr 5, 2004, in forum: XML
    Replies:
    0
    Views:
    775
    Peter Aberline
    Apr 5, 2004
  5. Bernd Oninger
    Replies:
    1
    Views:
    516
    Henry S. Thompson
    Jun 30, 2004
Loading...

Share This Page