<?xml version="1.0" encoding="UTF-8"?>
<!--

DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.

Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved.

The contents of this file are subject to the terms of either the GNU
General Public License Version 2 only ("GPL") or the Common Development
and Distribution License("CDDL") (collectively, the "License").  You
may not use this file except in compliance with the License.  You can
obtain a copy of the License at
http://glassfish.java.net/public/CDDL+GPL_1_1.html
or packager/legal/LICENSE.txt.  See the License for the specific
language governing permissions and limitations under the License.

When distributing the software, include this License Header Notice in each
file and include the License file at packager/legal/LICENSE.txt.

GPL Classpath Exception:
Oracle designates this particular file as subject to the "Classpath"
exception as provided by Oracle in the GPL Version 2 section of the License
file that accompanied this code.

Modifications:
If applicable, add the following below the License Header, with the fields
enclosed by brackets [] replaced by your own identifying information:
"Portions Copyright [year] [name of copyright owner]"

Contributor(s):
If you wish your version of this file to be governed by only the CDDL or
only the GPL Version 2, indicate your decision by adding "[Contributor]
elects to include this software in this distribution under the [CDDL or GPL
Version 2] license."  If you don't indicate a single choice of license, a
recipient has the option to distribute your version of this file under
either the CDDL, the GPL Version 2 or to extend the choice of license to
its licensees as provided above.  However, if you add GPL Version 2 code
and therefore, elected the GPL Version 2 license, then the option applies
only if the new code is made subject to such option by the copyright
holder.

        -->
<!DOCTYPE book [
<!ENTITY % ents SYSTEM "docbook.ent">
%ents;
]>
<section version="5.0" xml:id="other-miscellaneous-topics-compiling-dtd"
         xml:lang="en" xmlns="http://docbook.org/ns/docbook"
         xmlns:xlink="http://www.w3.org/1999/xlink"
         xmlns:ns5="http://www.w3.org/1999/xhtml"
         xmlns:ns3="http://www.w3.org/2000/svg"
         xmlns:ns="http://docbook.org/ns/docbook"
         xmlns:m="http://www.w3.org/1998/Math/MathML">
    <title>Compiling DTD</title>

    <para>The JAXB RI is shipped with an "experimental" DTD support, which
    let's you compile XML DTDs. It is marked "experimental" not because the
    feature is unstable nor unreliable, but rather because it's not a part of
    the JAXB specification and therefore the level of commitment to
    compatibility is lower.</para>

    <example>
        <title>To compile a DTD, run the XJC binding compiler as
        follows:</title>

        <programlisting language=""><![CDATA[$ xjc.sh -dtd test.dtd]]></programlisting>
    </example>

    <para>All the other command-line options of the XJC binding compiler can
    be applied. Similarly, the XJC ant task supports DTD. The generated code
    will be no different from what is generated from W3C XML Schema. You'll
    use the same JAXB API to access the generated code, and it is portable in
    the sense that it will run on any JAXB 2.0 implementation.</para>

    <para>DTD long predates XML namespace, although people since then
    developed various techniques to use XML namespaces in conjunction with
    DTD. Because of this, XJC is currently unable to reverse-engineer the use
    of XML namespace from DTD. If you compile DTDs that use those techniques,
    you'd either manuallly modify the generated code, or you can try a tool
    like <link
    xlink:href="http://www.thaiopensource.com/relaxng/trang.html">Trang</link>
    that can convert DTD into XML Schema in ways that better preserves XML
    namespaces.</para>

    <section xml:id="Customizations">
        <title>Customizations</title>

        <para>The customization syntax for DTD is roughly based on the
        ver.0.21 working draft of the JAXB specification, which is available
        at <link
        xlink:href="http://xml.coverpages.org/jaxb0530spec.pdf">xml.coverpages.org</link>.
        The deviations from this document are:</para>

        <itemizedlist>
            <listitem>
                <para>The <literal>whitespace</literal> attribute of the
                <literal>conversion</literal> element takes "
                <literal>preserve</literal>", " <literal>replace</literal>", and "
                <literal>collapse</literal>" instead of " <literal>preserve</literal>", "
                <literal>normalize</literal>", and " <literal>collapse</literal>" as
                specified in the document.</para>
            </listitem>

            <listitem>
                <para>The <literal>interface</literal> customization just generates
                marker interfaces with no method.</para>
            </listitem>
        </itemizedlist>
    </section>

    <section xml:id="Compiling_DTD_from_Maven2">
        <title>Compiling DTD from Maven2</title>

        <example>
            <title>The following POM snippest describes how to invoke XJC to
            compile DTD from a Maven 2 project:</title>

            <programlisting language="xml"><![CDATA[<plugin>
  <groupId>org.jvnet.jaxb2.maven2</groupId>
  <artifactId>maven-jaxb2-plugin</artifactId>
  <executions>
    <execution>
      <goals>
        <goal>generate</goal>
      </goals>
      <configuration>
        <!--  if you want to put DTD somewhere else
        <schemaDirectory>src/main/jaxb</schemaDirectory>
        -->
        <extension>true</extension>
        <schemaLanguage>DTD</schemaLanguage>
        <schemaIncludes>
          <schemaInclude>*.dtd</schemaInclude>
        </schemaIncludes>
        <bindingIncludes>
          <bindingInclude>*.jaxb</bindingInclude>
        </bindingIncludes>
        <args>
          <arg>-Xinject-listener-code</arg>
        </args>
      </configuration>
    </execution>
  </executions>
  <dependencies>
    <dependency>
      <groupId>org.jvnet.jaxb2-commons</groupId>
      <artifactId>property-listener-injector</artifactId>
      <version>1.0</version>
    </dependency>
  </dependencies>
</plugin>]]></programlisting>
        </example>

        <example>
            <title>The dependencies section inside the plugin element can be
            used to specify additional XJC plugins. If you'd like to use more
            recent version of the JAXB RI, you can specify a dependency to XJC
            here to do so, like this:</title>

            <programlisting language="xml"><![CDATA[<dependency>
  <groupId>com.sun.xml.bind</groupId>
  <artifactId>jaxb-xjc</artifactId>
  <version>2.1.2</version>
</dependency>]]></programlisting>
        </example>

        <para>The complete sample project is available from <link
        xlink:href="http://weblogs.java.net/blog/kohsuke/archive/20070130/dtd.zip">here</link>.</para>
    </section>
</section>
