O'Reilly logo

XML Hacks by Michael Fitzgerald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Create an XML Schema Document from an Instance or DTD

There are several tools that can help you generate an XML Schema document from either an instance or a DTD. This hack shows you how to get the job done with little fuss.

This hack walks you through the process of creating an XML Schema document from an XML document or a DTD. The DTD2XS utility uses a DTD, but the XSD Inference, Trang, Relaxer, and xmlspy tools all rely on an instance. Each of the following sections walks you through the simple steps necessary to get the job done with any of the tools.

LuMriX.net’s DTD2XS

LuMriX.net (http://www.lumrix.net) offers a Java tool for creating an XML Schema from a DTD. Their tool is called DTD2XS (https://github.com/reposit/dtd2xs). This tool comes with a command-line and a browser interface. We’ll cover the command-line interface in this hack.

Download the tool and extract the archive. In the archive, you will find the files dtd2xs.class, dtd2xsd.class, xurl.class, and complextype.xsl. Copy these files to the working directory and type the following command (which assumes that the working directory is in the classpath):

java dtd2xsd time.dtd

The tool will generate the following output (Example 5-10).

Example 5-10. DTD2XS tool output

dtd2xs: dtdURI file:///C:\Hacks\examples\time.dtd dtd2xs: resolveEntities true dtd2xs: ignoreComments true dtd2xs: commentLength 100 dtd2xs: commentLanguage null dtd2xs: conceptHighlight 2 dtd2xs: conceptOccurrence 1 dtd2xs: conceptRelation element attribute ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required