Generating XML files from DTDs

You can generate an XML file from your DTD if you want to quickly create an XML file based on your DTD file. Generating an XML file from your DTD saves you time by creating an XML file that is already associated with your DTD, and contains at least some of the elements and attributes in your DTD.

After you have generated your XML file, you can further customize it in the XML editor.

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

To create an XML file from a DTD file, complete the following steps:

  1. In the Navigator view, right-click the DTD file that you want to work with and select Generate > XML File.
  2. Select a project or folder to contain the XML file and type a name for the file in the File Name field, then click Next. The name of the file must end in .xml.
  3. Select the Root element of the XML file. The root element of an XML file is the element that contains all other elements in that file. All the elements that you have defined in the DTD will be shown in the Root element list.
  4. Select from the following content options:
    • Create optional attributes: both mandatory and optional attributes will be generated.
    • Create optional elements: both mandatory and optional elements will be generated.
    • Create first choice of required choice: the first option of a required choice will be generated in your XML file.
    • Fill elements and attributes with data: any elements and attributes generated will be filled with sample data.
    If you do not select any of these options, then only the minimum amount of content required for the XML file will be created.
  5. Specify the Public ID or System ID. You do not need to specify both. If you do, the Public ID will be used before the System ID.
  6. Click Finish.

The XML file will only contain the selected root element and any elements or attributes contained in the root element. You can now add elements, attributes, entities, and notations to the XML file, however, they must follow the rules established in the DTD that you used to create the XML file.

Related concepts
XML editor
Related tasks
Creating XML files
Generating XML files from XML schemas
Editing XML files