Thursday, July 22, 2010

PMC Open Access JAXB Bindings

If you're trying to generate Java JAXB for the NLM Journal Publishing DTD http://dtd.nlm.nih.gov/publishing/w3c-schema.html you're going to run into some problems with the bindings. Some of these are related to MathML and some are related to the NLM schema. In particular mine look like:
Trying to override old definition of datatype resources
OpenAccesJaxb:
     [exec] parsing a schema...
     [exec] [ERROR] Property "Title" is already defined. Use <jaxb:property> to resolve this conflict.
     [exec]   line 1185 of http://dtd.nlm.nih.gov/publishing/3.0/xsd/journalpublishing3.xsd
     [exec] [ERROR] The following location is relevant to the above error
     [exec]   line 1227 of http://dtd.nlm.nih.gov/publishing/3.0/xsd/journalpublishing3.xsd
     [exec] [ERROR] Element "{http://www.w3.org/1998/Math/MathML}ms" shows up in more than one properties.
     [exec]   line 132 of http://dtd.nlm.nih.gov/publishing/3.0/xsd/ncbi-mathml2/presentation/scripts.xsd
     [exec] [ERROR] The following location is relevant to the above error
     [exec]   line 113 of http://dtd.nlm.nih.gov/publishing/3.0/xsd/ncbi-mathml2/presentation/tokens.xsd
     [exec] [ERROR] Property "MiOrMoOrMn" is already defined. Use <jaxb:property> to resolve this conflict.
     [exec]   line 132 of http://dtd.nlm.nih.gov/publishing/3.0/xsd/ncbi-mathml2/presentation/scripts.xsd
     [exec] [ERROR] The following location is relevant to the above error
     [exec]   line 138 of http://dtd.nlm.nih.gov/publishing/3.0/xsd/ncbi-mathml2/presentation/scripts.xsd
     [exec] [ERROR] Element "{http://www.w3.org/1998/Math/MathML}ms" shows up in more than one properties.
     [exec]   line 138 of http://dtd.nlm.nih.gov/publishing/3.0/xsd/ncbi-mathml2/presentation/scripts.xsd
     [exec] [ERROR] The following location is relevant to the above error
     [exec]   line 113 of http://dtd.nlm.nih.gov/publishing/3.0/xsd/ncbi-mathml2/presentation/tokens.xsd
     [exec] Failed to parse a schema.
     [exec] Result: -1

The easiest solution is to add a custom bindings file. Thanks to this useful post the MathML errors are easily resolved. Then you just need to add one more to fix the "title" property problem. My final XJB file ends up looking like:
<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://java.sun.com/xml/ns/jaxb" xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="2.0">

  <bindings schemaLocation="http://dtd.nlm.nih.gov/publishing/3.0/xsd/journalpublishing3.xsd"
    node="/xsd:schema/xsd:element[@name='bio']//xsd:element[@ref='title']">
    <property name="biotitle" />
  </bindings>

  <bindings schemaLocation="http://dtd.nlm.nih.gov/publishing/3.0/xsd/ncbi-mathml2/common/common-attribs.xsd"
    node="/xsd:schema/xsd:attributeGroup[@name='Common.attrib']/xsd:attribute[@name='class']">
    <property name="clazz" />
  </bindings>

  <bindings schemaLocation="http://dtd.nlm.nih.gov/publishing/3.0/xsd/ncbi-mathml2/presentation/scripts.xsd"
    node="/xsd:schema/xsd:group[@name='mmultiscripts.content']">
    <property name="content" />
  </bindings>

</bindings>
and my ant task to generate the bindings looks like:
<target name="OpenAccesJaxb" description="Generate the Open Access JAXB bindings">
  <exec executable="xjc">
    <arg value="-b"/>
    <arg value="pmcOa.xjb"/>
    <arg value="-d"/>
    <arg value="src"/>
    <arg value="-p"/>
    <arg value="${pmc.oa.package.jaxb}"/>
    <arg value="${pmc.oa.schema}"/>
  </exec>
</target>

Where the last two properties point to the package the code should be generated in and pubmed schema location respectively...

No comments:

Post a Comment