Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Java objects from XSD?

Reply
Thread Tools

Java objects from XSD?

 
 
Wojtas
Guest
Posts: n/a
 
      09-19-2007
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


 
Reply With Quote
 
 
 
 
Steve W. Jackson
Guest
Posts: n/a
 
      09-19-2007
In article <fcqn1v$8tk$(E-Mail Removed)>,
"Wojtas" <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      09-19-2007
On Wed, 19 Sep 2007 10:33:35 +0200, "Wojtas"
<(E-Mail Removed)> 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
 
Reply With Quote
 
Stefan Ram
Guest
Posts: n/a
 
      09-19-2007
"Wojtas" <(E-Mail Removed)> 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(); }}

 
Reply With Quote
 
Manish Pandit
Guest
Posts: n/a
 
      09-19-2007
On Sep 19, 1:33 am, "Wojtas" <(E-Mail Removed)> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
class objects, method objects, function objects 7stud Python 11 03-20-2007 06:05 PM
Finding an accompanying java book to Objects first with java SIDSARAN@gmail.com Java 8 01-22-2007 07:14 AM
trouble handling java objects from inside java methods via C badduck Java 3 09-01-2005 05:20 AM
C++ objects that act like Java/C# objects. Steven T. Hatton C++ 8 06-28-2005 05:26 PM
JRuby: How does one keep Java objects as Java objects so they can be used in method calls? Steve Drach Ruby 3 06-19-2004 11:25 PM



Advertisments