Schema XML Generator

The XML Schema (XSD) to XML instance generator tool is useful for generating sample XML messages based on an XML Schema (XSD) document. It is accessible under XSD->XML tab under the Tools tab.

Figure 9.12. XML Generator - Tool view

XML Generator - Tool view


The first step is to add a schema file by uploading it to the server. This is done by clicking on ‘Add’ and uploading either a single schema file (.xsd) or a zip file containing the main schema file and its references.

Figure 9.13. XML Generator - Schemas list

XML Generator - Schemas list


The uploaded schema file is displayed in a table on the left and clicking on the schema file name, displays the contents in the editor (Schema tab) on the right. The ‘Save’ and ‘Revert’ buttons under the Schema tab can be used to make changes to the schema being edited or revert any unsaved changes.  

When the schema is displayed, the Root Element drop-down box displays all the root elements declared in the schema file, which can be used as the starting root element in the generated XML file.   The screenshot below shows the process of selecting a root element in a schema file:

Figure 9.14. XML Generator - Root elements list

XML Generator - Root elements list


XML Generation Options

The XML instance generation can be configured through certain options which are available by clicking on the Options button. The options dialog is as shown below:

Figure 9.15. XML Generator - options

XML Generator - options


Generate optional Attributes

Controls whether attributes which are specified as optional in the schema will be generated

Generate optional Elements

Controls whether attributes which are specified as optional in the schema will be generated

Generate comments for schema particles

Controls whether XML comments (of the form <!-- … -->) will be generated for the schema particles

Max repeating elements

Controls the number of duplicate elements to generate when the maxOccurs attribute value is ‘unbounded’ for the element. Default value = 3

Max recursive depth

Controls the number of recursive calls to make when processing an element which refers to itself, or to another element which in turn refers to the element referring it. Default value = 1

Choice Branch

Controls which element to select when processing the <xs:choice/> element. The available options are: First and Random. First will result in the first element under choice getting selected and Random results in a random pick of the element to process

Output Format

Controls whether the generated XML will be in compact form or pretty-printed

Clicking on ‘Generate’ will result in the currently selected options being applied to the XSD->XML generation process. A new tab displaying the generated XML is shown next to the ‘Schema’ tab for every generation.