How to Convert a DTD to XSD
Document Type Definition (DTD) is an older standard that defines the schema for an XML document. An XML document provides Web pages with a list of logical data. For instance, an XML document can contain a list of customers. The DTD file creates the layout that defines each customer field, so the Web engine knows what to expect, such as data type and name, when displaying the content to the user. XSD is a newer standard, so you can convert your older DTD files to XSD.
Instructions
-
-
1
Create the XSD schema definition tags. Place the following code at the top of your file, which indicates to the Web engine that the file is an XSD file:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.yourdomain.com"
xmlns="http://www.yourdomain.com">
The "yourdomain" is replaced with your own website domain.
-
2
Add the tags that contain the XML data record definitions. Within these tags contain the translation from DTD to XSD. Add the following code to your file:
<xs:element name="customer">
<xs:complexType>
<xs:sequence>
</xs:sequence>
</xs:complexType>
</xs:element>
-
-
3
Translate each DTD tag to XSD. The following code is an example of a DTD record that describes XML data fields for a customer's first and last name:
<!ELEMENT first_name (#PCDATA)>
<!ELEMENT last_name (#PCDATA)>
Within the tags created in step two, those two data tags translate to the following in XSD:
<xs:element name="first_name" type="xs:string"/>
<xs:element name="last_name" type="xs:string"/>
-
1
Tips & Warnings
Continue to replace each DTD line with a new XSD field. An XSD file can grow to be several fields or only a few, depending on the size of the DTD file. After each field is translated, the new XSD file provides a complete schema for your XML file.
References
- Photo Credit computer image by Orlando Florin Rosu from Fotolia.com