Syntext dtd2xs v2.0 User's Guide


Table of Contents

Introduction
Installation
Typical Use of dtd2xs
Using dtd2xs to Convert DTD's with Namespaces
Command-line Options

Introduction

Syntext dtd2xs is an XML DTD to W3C Schema converter. The utility correctly handles complex and modularized DTDs (such as Docbook) and supports DTDs with namespaces (i.e. DTDs where elements and attributes may have namespace prefixes).

dtd2xs is able to use parameter entity information from original DTD. It is used as a hint to form an attribute groups in a resulting Schema. Currently dtd2xs does not make use of model groups because this feature support doesn't really improve internal efficiency of validators (different FSMs are generated for each complex content anyway).

Installation

Just copy dtd2xs executable to the preferred location.

Important

Under Windows, make sure that MSVCR71.DLL and MSVCP71.DLL are in your path.

Typical Use of dtd2xs

Note

Dtd2Xs functionality is fully accessable from both command line (run dtd2xs with some command line arguments) and GUI (run dtd2xs without any command line arguments).

Dtd2Xs GUI is analogous to command line interface described below.

Use of dtd2xs for DTDs which do not use namespaces is pretty straightforward:

dtd2xs input.dtd output.xsd         

Utility correctly handles relative external entity references in the source dtd. E.g. to make Docbook schema under Linux you may just execute the following command:

dtd2xs /usr/share/sgml/docbook/xml-dtd/docbookx.dtd docbookx.xsd         

Using dtd2xs to Convert DTD's with Namespaces

To correctly handle namespaces, dtd2xs must be provided with namespace mapping and target namespace prefix information from command-line (it is not possible to deduce it from DTD itself). Default behavior of dtd2xs is to ignore elements with unmapped prefixes.

In the following examples we will use XSL Formatting Objects (XSL-FO) DTD as an example. The DTD file, fo.dtd, contains definition of a standard XSL-FO plus extensions for RenderX XSL-FO renderer. Standard elements and attributes are defined with fo prefix; RenderX extensions use different namespace and have rx prefix.

To make 'pure' XSL-FO Schema, use:

dtd2xs -t fo -m fo:http://www.w3.org/1999/XSL/Format fo.dtd

Note that -t option is used to specify target namespace prefix (fo), and -m option is used to map this prefix into namespace URI.

To make 'full' Schema, which defines both standard XSL-FO constructs and RenderX extensions, use:

dtd2xs -t fo -m fo:http://www.w3.org/1999/XSL/Format -m rx:http://www.renderx.com/XSL/Extensions -i rx:rx.xsd fo.dtd fo+rx.xsd dtd2xs -t rx -m rx:http://www.renderx.com/XSL/Extensions fo.dtd rx.xsd

We actually need two commands here. First one defines mappings for two namespace prefixes (fo and rx). fo is used as a target namespace prefix and additional option -i rx:rx.xsd means "import components with rx prefix from schemaLocation rx.xsd). In the second command, we extract RenderX extensions into the separate schema file rx.xsd, which will be used (imported) by first Schema file fo+rx.xsd. It may look cumbersome, but W3C XML Schema standard does not allow definition of elements for different namespaces in the single Schema file.

Another caveat is handling attributes for which element namespace is different from attribute namespace. Since a validator must be able to reference definitions of such attributes from an imported schema, dtd2xs generates definitions of such attributes at the top level of the schema.

Note

You must specify target prefix and prefix mappings if your DTD contains namespaces. Without this, dtd2xs will probably generate incorrect Schema.

Command-line Options

dtd2xs [-q] [-A] [-E] [-t target-ns-prefix] [-mns-prefix:URI ...] [-n ns-prefix ...] [-i ns-prefix:[loc] ...] {input.dtd} {output.xsd}

Options:

-t target-ns-prefix

Specify target namespace prefix for which dtd2xs must generate Schema. If your DTD contains multiple prefixes, you probably will need to generate separate Schema for each of them, and use -i option to specify schema import relationships.

-m ns-prefix:URI

Create mapping for namespace prefix ns-prefix to the namespace URI. If you do not map all used prefixes, dtd2xs may fail to generate correct Schema. You may specify multiple -m options in the same command line.

-i ns-prefix[:file-location]

Specifies that current schema must import schema with prefix ns-prefix. With this option dtd2xs may generate references to the components of other schema. Optionally, file-location may be specified (it is translated to schemaLocation attribute in Schema import instruction). You may specify multiple -i options in the same command line.

-n ns-prefix

Explicitly omit references to components with ns-prefix. You may specify multiple -n options in the same command line.

-q

Don't print copyright information when running the utility.

-A

Don't attempt to group attributes into the attribute groups. By default dtd2xs attempts to use parameter entity references as a hint for making attribute groups. With this option, attributes will be defined locally for each element. Usage of this option may increase size of the DTD considerably (e.g. XSL-FO Schema will be about 1.6M instead of 85K without this option).

-E

Do not omit empty attribute groups (by default dtd2xs does that). However it may not be desirable in some cases (e.g. when you plan to extend generated schema manually).