Please enable JavaScript to view this site.

Altova XMLSpy 2020 Enterprise Edition

The Convert DTD to Schema command is enabled when a DTD is the active document. It converts a DTD into an XML Schema document (XSD).

 

The command pops up the Convert DTD to W3C Schema dialog (screenshot below), in which you can select whether complex elements should be converted into elements or complex types. On clicking OK, you are prompted to select a location at which to save the generated XSD file. Click Save to carry out the conversion. The XSD file is generated and opened in XMLSpy.

dlgDTD2XSD

When you convert a DTD to XML Schema, XMLSpy makes a few assumptions because of the limited information available. Most notably, the values of certain DTD components are treated literally rather than having their semantics parsed. This is because the program cannot know which of several possible usages is intended. In these cases, you should modify the generated conversion.

 

In any case, you should carefully examine the generated conversion to see if you can enhance it. A few areas in which improvements may be required are listed below.

 

 

Attribute Datatyping

DTDs allow for only 10 attribute datatypes, whereas XML Schemas, for instance, allow for more than 40 datatypes plus derived datatypes. You may wish to enhance a generated XML Schema, for example, by using a more restrictive datatype. Note that when an XML Schema is converted to DTD datatype information will be lost.

 

 

Namespaces

DTDs are not namespace-aware. As a result, if namespaces are to be specified in a DTD they must be hard-coded into element and attribute names. This could pose challenging problems when converting from one schema to another.

 

 

Entities

XML Schema does not have equivalents for the general entity declarations of DTDs. When XMLSpy converts a DTD to an XML Schema, it ignores entity declarations.

 

 

Unparsed data declarations

DTDs and XML Schemas use different mechanisms for handling unparsed data. This is explained in more detail below.

 

DTDs use the following mechanism:

 

A notation is declared consisting of a name and an identifier, for example:
<!NOTATION gif SYSTEM "image/gif">

You declare the entity, for example:
<!ENTITY cover_img SYSTEM "graphics/cover_img.gif" NDATA gif>

Typically, you specify an attribute type of ENTITY on the relevant attribute, for example:<!ELEMENT img EMPTY>

      <!ATTLIST img format ENTITY #REQUIRED>

 

In XML Schema, the corresponding mechanism is as follows:

 

Declare a notation. This functions in the same way as for the DTD.

<xs:notation name="gif" public="image/gif"/>

 

Note that the public attribute is mandatory and holds the identifier. An optional system attribute holds the system identifier and is usually an executable that can deal with resources of the notation type.

You associate the notation declaration with a given attribute value using the NOTATION datatype. You cannot, however, use the NOTATION datatype directly, but must derive another datatype from the NOTATION datatype.

<xs:simpleType name="formatType">

  <xs:restriction base="xs:NOTATION">

     <xs:enumeration value="gif"/>

     <xs:enumeration value="jpeg"/>

  </xs:restriction>

</xs:simpleType>

You associate the attribute with the datatype derived from the NOTATION datatype, e.g.

<xs:complexType name="imgType">

  <xs:attribute name="height"/>

  <xs:attribute name="width"/>

  <xs:attribute name="location"/>

  <xs:attribute name="format" type="formatType" use="required"/>

</xs:complexType>

<xs:element name="img" type="imgType"/>

 

When you convert a DTD to an XML Schema, XMLSpy does the following:

 

Something like

<!ATTLIST image format ENTITY #REQUIRED

...>

 

is converted to

<xs:attribute name="format" type="xs:ENTITY" use="required"/>

 

And something like

<!NOTATION gif SYSTEM "image/gif">

 

is converted to

<xs:notation name="gif" system="image/gif"/>

 

You should therefore make the following modifications:

 

1.In notations like <xs:notation name="gif" system="image/gif"/> replace system with public, and add an optional system identifier if required.

2.Derive a datatype from the NOTATION datatype as described above for formatType.

3.Associate the derived datatype with the relevant attribute.

 

Note:According to the XML Schema specification, you do not need to—or cannot, depending on your viewpoint—declare an external entity.

 

© 2019 Altova GmbH