Generate Instances Based on Schemas

Use xmlspy or Sun’s Instance Generator to create instances of DTDs or other schemas.

Perhaps you need to generate XML instances of a given schema to create a test suite or you want a collection of instance files for some other reason. xmlspy (http://www.xmlspy.com) can create a single instance of a DTD or XML Schema document, but the Sun Instance Generator, a Java program, can create many XML instances based on a DTD, RELAX NG, Relax, or XML Schema. If you want a quick look at a single instance, xmlspy may be adequate for you. However, if you need a set of files, including some with intentional errors in them, Sun’s tool is probably the way to go. This hack shows you how to use both tools.

Generating an Instance with xmlspy

These instructions assume that you have already downloaded and installed xmlspy 2004 Professional or Enterprise Edition (this won’t work with the Home Edition). Follow these steps to create an instance of the DTD time.dtd:

  1. Open xmlspy.

  2. Choose File Open and the Open dialog box appears. Navigate to the working directory of files from the book file archive and select the file time.dtd. Then click the Open button.

  3. Choose DTD/Schema Generate sample XML file. The Generate sample XML file dialog box appears. All the radio buttons should be selected by default, and the repeatable elements text box should contain the number 1. This means that xmlspy will generate a document that includes all non-mandatory elements and attributes, ...

Get XML Hacks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.