The dtd option enables Relaxer to generate a DTD instance from a resource specified by a parameter.
The dtd option takes no parameters. Specifying the dtd option indicates that you want Relaxer to generate a DTD.
The dtd option generates a DTD instance from the resource specified by the parameter.
You can get a DTD schema from a RELAX NG schema using Relaxer.
List 27.2.3.1[dtdRng.rng] is a RELAX NG schema.
<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"> <start> <ref name="account"/> </start> <define name="account"> <element name="account"> <attribute name="accountNo"> <data type="token"/> </attribute> <element name="balance"> <data type="int"/> </element> <element name="owner"> <data type="token"/> </element> <optional> <ref name="address"/> </optional> <zeroOrMore> <ref name="phone"/> </zeroOrMore> </element> </define> <define name="address"> <element name="address"> <attribute name="zip"> <data type="token"/> </attribute> <text/> </element> </define> <define name="phone"> <element name="phone"> <attribute name="area"> <data type="token"/> </attribute> <data type="token"/> </element> </define> </grammar>
To generate a DTD with Relaxer, enter the following command:
$ relaxer -dtd dtdRng.rng
As a result, Relaxer generates one file:
The artifact file from the DTD generator is shown in List 27.2.3.2[dtdRng.dtd].
<!-- Generated by Relaxer 1.0rc3b --> <!-- Sun Aug 10 05:49:46 GMT+09:00 2003 --> <!ELEMENT phone (#PCDATA)> <!ATTLIST phone area CDATA #REQUIRED> <!ELEMENT balance (#PCDATA)> <!ELEMENT account (balance, owner, address?, phone*)> <!ATTLIST account accountNo CDATA #REQUIRED> <!ELEMENT owner (#PCDATA)> <!ELEMENT address (#PCDATA)> <!ATTLIST address zip CDATA #REQUIRED>
You can also get a DTD schema from an XML document using Relaxer.
List 27.2.4.1[dtdXml.xml] is a sample XML document.
<account accountNo="12345"> <balance>102030</balance> <owner>XML Taro</owner> <address zip="213">Yokohama</address> <phone area="123">456-7890</phone> <phone area="090">123-4567</phone> </account>
To generate a DTD with Relaxer, enter the following command:
$ relaxer -dtd dtdXml.xml
As a result, Relaxer generates one file:
The artifact file from the DTD generator is shown in List 27.2.4.2[dtdXml.dtd].
<!-- Generated by Relaxer 1.0rc3b --> <!-- Sun Aug 10 05:50:03 GMT+09:00 2003 --> <!ELEMENT phone (#PCDATA)> <!ATTLIST phone area CDATA #REQUIRED> <!ELEMENT balance (#PCDATA)> <!ELEMENT account (balance, owner, address, phone+)> <!ATTLIST account accountNo CDATA #REQUIRED> <!ELEMENT owner (#PCDATA)> <!ELEMENT address (#PCDATA)> <!ATTLIST address zip CDATA #REQUIRED>