# Generating XML schemas from DTD files

Generating an XML schema from a DTD file enables you to create an XML schema that is automatically populated with elements and attributes from your DTD file. This can save you time if you want to use an XML schema rather than a DTD file to validate your XML file, but you want to use the rules already set up in your DTD file.

The following instructions were written for the Resource perspective, but they will also work in many other perspectives.

To generate an XML schema file from a DTD file, follow these steps:

1. In the Navigator view, right-click your DTD and click Generate > XML Schema.
2. Select the project or folder that will contain the schema.
3. Accept the default name or type a new one and click Next.
4. If you want to create an XML schema that will contain your DTD file and any DTD files it references, click the Create one XML schema that includes all the DTD files radio button.
5. Otherwise, if you want to create an individual schema for your DTD file and each DTD file it references, click the Create an XML schema for each DTD file radio button.
6. Click Finish.

Your schemas appears in the Navigator view. They will have the same name as the DTD file they were generated from (if you accepted the default value in the File name field when you generated the XML schema).

Any entities that were in your DTD file will not be in the XML schema (as entities are not supported in XML schemas). However, any elements or attributes that referred to an entity will carry over that value to an XML schema.

For example, you have a DTD called "Legal" that contains an entity called "Copyright". The value of the entity is "Copyright 2004. MyCompany Publishing" . In your DTD, you have an element called "MyCopyright", which refers to the entity Copyright. After you create the XML schema, the Copyright entity will not appear in the XML schema, however, its value is carried over (that is, MyCopyright will have the value: Copyright 2004. MyCompany Publishing ).

All elements and attributes that existed in your DTD file will exist in the XML schema file.

Elements in your DTD with a content model of (#PCDATA) (and no attributes) appear empty in the XML schema editor. They are marked as having Built-in simple types of `string`. That is, a DTD element with a value of (#PCDATA) will map to an XML schema element with an XML schema primitive type `string`.

Note: When you generate an XML schema from a DTD file that contains Hebrew or Arabic elements, certain element names might be encoded with their equivalent hexadecimal Hebrew and Arabic encoding values. To avoid this problem, change the encoding attribute of the original DTD or XML schema file to UTF-8 before performing the generation: That is, the XML declaration should be: `<?xml version="1.0" encoding="UTF-8"?>` The list of affected encoding values is: ISO-8859-8-I, ISO-8859-8, Windows-1256, and ISO-8859-6.

Related tasks
Creating DTDs

Related information
Editing XML schemas

(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.