views:

256

answers:

1

Given a Dataset XSD file, is it possible to generate java classes, that don't make use of System.Data? I've tried running a test using JAXB's XJC tool, but it doesn't produce anything terribly useful.

Update: I've tried XmlBeans also, following Fernando's suggestion, and it generates something similar to the XJC output - that is, class representations of the tables, but without any columns, constraints, or rows. I can add these things in a facade, but ideally they would be generated by whatever XSD compiler was used.

+1  A: 

You could try XMLBeans instead of JAXB API. You can invoke it be means of command line command or just use an ANT script. I past the part of a build.xml file that invokes XMLBeans to compile XSD to a jar file.

<taskdef name="xmlbean" classname="org.apache.xmlbeans.impl.tool.XMLBean" classpathref="classpath"/>


<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!--  Crea y compila las clases del modelo           -->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->

<target name="build" description="--> crea las clases a partir del schema">
 <!-- Borra los fuentes del modelo -->
 <delete quiet="true" dir="${build.dir}/src" />

 <mkdir dir="${build.classes}"/>

 <!-- Construye fuentes asociadas y crea las clases -->
 <xmlbean srcgendir="${build.dir}/src" classpathref="classpath" classgendir="${build.classes}">
  <fileset dir="${src.dir}" excludes="**/*.xsd"/>
     <fileset dir="${schemas.dir}" includes="**/*.*"/>
 </xmlbean>

 <javac srcdir="${src.dir}" 
    destdir="${build.classes}" 
    encoding="Windows-1252" 
    debug="${debug}" 
    debuglevel="${debuglevel}" 
    deprecation="${deprecation}" 
    verbose="${verbose}" 
    optimize="${optimize}" 
    source="${source}" 
    target="${target}">
    <classpath refid="classpath" />
 </javac>
</target>
Fernando Miguélez
The XmlBeans scomp compiler (is this what you meant?) generates reasonable code from an MS-Dataset XSD, but it looses all information about columns, constraints, etc. I get a similar result from XJC.
Andy