xml schema


Since last year I have been working on a REST-version of a webservice to access a handle system server. XML schema is a good way to describe the service interface of such a webservice.

Motivated by the current discussion at the handle mailinglist I finally pushed it to version 0.1 which I would regard rather as a proof of concept and a contribution to this discussion. This schema can be used as a starting point to design a custom REST interface to a handle system server or even as a means to describe a handle site’s data structure and constraints.

Designing the schema I had JAXB java data binding in mind and the possibility to extend handle data types, especially using xml-formatted data in the data section of handle values. I also wanted the representation of handle values in instance documents to be human readable so that clients can easily deal with the semantics of handles.

Have a look at the handle_schema.zip. The schema files are commented und you will also find an example which demonstrates custom datatypes usage.

Couldn’t find it explicitly stated anywhere probably because it’s quite simple (watch \linebreaks):

<xsd:simpleType name="urnType">
 
      <xsd:annotation><xsd:documentation>
 Regular expression to validate RFC 2141 URN syntax.
"urn:[a-zA-Z0-9][a-zA-Z0-9-]{1,31}:([a-zA-Z0-9()+,.:\linebreak
=@;$_!*'-]|%[0-9A-Fa-f]{2})+"
      </xsd:documentation></xsd:annotation>
 
      <xsd:restriction base="xsd:anyURI">
          <xsd:pattern 
 
value="urn:[a-zA-Z0-9][a-zA-Z0-9-]{1,31}:\linebreak
([a-zA-Z0-9()+,.:=@;$_!*'-]|%[0-9A-Fa-f]{2})+"
 
/>
      </xsd:restriction>
</xsd:simpleType>

Problem:Create an XML Schema which will be binded by JAXB to a class structure following certain constrains. You have certain degrees of freedom for your schema design and later you might also use schema annotations provided by JAXB. Modularize your XML schemas, simplest example is: A.xsd uses &lt;include&gt; to include declarations from schema B.xsd.

I want to try Netbeans’ excellent schema design features. Eventually I want to publish the schemas in a WAR deployed in a web container. That’s why I decided to put the files directly into the /web directory of the web-project.

Proposed Solution:
Trying to use Netbeans’ JAXB Wizard (or see http://wiki.netbeans.org/JAXBWizard) to create a JAXB Binding for A.xsd you will meet certain limitations: schema file changes won’t be visible to the “Regenerate” operation. You could edit the copy of A.xsd created by the JAXB Wizard in src/conf/xml-resources/jaxb/name_of_the_binding to make changes visible to the task but that will not see changes in B.xsd. The reason is that the ant tasks created by the JAXB Wizard do not provide this kind of granularity.

So the solution for me was to create the binding using JAXB Wizard, then overriding the created tasks. I copied &lt;target name="jaxb-code-generation" ... from nbproject/xml_binding_build.xml to build.xml and customized the parameters of the XJC task:

  <import file="nbproject/build-impl.xml"/>
 
    <target name="ask-something">
    <input message="Do you like to customize the best IDE of all times?"
    validargs="Yes, Yes"
    addproperty="answer"/>
<echo message="Answer Yes! ${answer}" />
    </target>
 
     <target name="jaxb-code-generation" depends="xjc-typedef-target">
        <mkdir dir="build/generated/addons/jaxb" xmlns:s="http://xml.netbeans.org/schema/JAXBWizConfig"/>
        <mkdir dir="build/generated/jaxbCache" xmlns:s="http://xml.netbeans.org/schema/JAXBWizConfig"/>
        <mkdir dir="${build.classes.dir}" xmlns:s="http://xml.netbeans.org/schema/JAXBWizConfig"/>
        <mkdir dir="build/generated/jaxbCache/HandleSystemBinding"/>
 
<!-- remove catalog attribut here or change refs in catalog.xml : catalog="catalog.xml" -->
        <xjc package="de.gbv.examples.handesystembinding" destdir="build/generated/jaxbCache/HandleSystemBinding">
            <classpath>
                <pathelement location="${src.dir}"/>
                <pathelement path="${jaxbwiz.xjcrun.classpath}"/>
            </classpath>
            <arg value="-xmlschema"/>
            <arg value="-verbose"/>
 
            <!-- customize this -->
            <schema file="web/A.xsd"/>
 
            <depends file="web/B.xsd"/>
            <!-- end customization -->
 
            <produces dir="build/generated/jaxbCache/HandleSystemBinding"/>
        </xjc>
 
        <copy todir="build/generated/addons/jaxb">
            <fileset dir="build/generated/jaxbCache/HandleSystemBinding"/>
        </copy>
        <javac destdir="${build.classes.dir}" srcdir="build/generated/addons/jaxb" source="${javac.source}" target="${javac.target}" xmlns:s="http://xml.netbeans.org/schema/JAXBWizConfig">
            <sourcepath location="${src.dir}"/>
            <classpath path="${jaxbwiz.gensrc.classpath}"/>
        </javac>
    </target>

Note: Later discussions on netbeans issue tracking showed that there is a simpler way by first running “refresh” on the bindings schema and then doing “clean and build”. For that you don’t need to modify the ant target, nevertheless the discussed modification gives you this with just the “Regenerate” action click.