To generate sample XML files from an XML Schema use the Generate Sample XML Files... dialog. It is opened with the action → . The action is available also on the contextual menu from the schema Design page.
Complete the dialog as follows:
Schema's URL. Last used URLs are displayed in the drop-down box.
Displays the namespace of the selected schema.
After the list is selected, a list of elements is displayed in the combo box. The user should choose the root of the XML documents to be generated.
Path to the folder where the generated XML instances will be saved.
Generated files' names have the following format: prefixN.extension, where prefix and extension are specified by the user and N represents an incremental number from 0 up to Number of instances - 1.
The number of XML files to be generated.
When checked, the first generated XML file will be opened in editor.
Here the user can specify the default namespace as well as the proxies (prefixes) for namespaces.
The current settings can be saved for further usage with the Export settings button, and reloaded when necessary with the Load settings button.
The Options tab becomes active only after the URL field is filled-in and a schema is detected. It allows the user to set specific options for different namespaces and elements.
Allows the user to define settings for:
All elements from all namespaces. This is the default setting and it can also be accessed from Options -> Preferences -> XML / XML Instance Generator.
All elements from a specific namespace.
A specific element from a specific namespace.
When checked, all elements will be generated, including the optional ones (having the minOccurs attribute set to 0 in the schema).
When checked, all attributes will be generated, including the optional ones (having the use attribute set to optional in the schema.)
Controls the content of generated attributes and elements. Several choices are available:
None - No content is inserted;
Default - Inserts a default value depending of data type descriptor of the respective element/attribute. The default value can be either the data type name or an incremental name of the attribute or element (according to the global option from the XML instance generator preferences page). Please note that type restrictions are ignored for this option for generating the values of elements and attributes. For example if an element is of a type that restricts an xs:string with the xs:maxLength facet in order to allow strings with a maximum length of 3 the XML instance generator tool may generate string element values longer than 3 characters. If you need to generate valid values please use the Random option.
Random - Inserts a random value depending of data type descriptor of the respective element/attribute.
Allows the user set the preferred number of repeating elements related with minOccurs and maxOccurs defined in XML Schema.
If the value set here is between minOccurs and maxOccurs, that value will be used;
If the value set here is less than minOccurs, the minOccurs value will be used;
If the value set here is greater than maxOccurs, that value will be used.
Option to set the maximum allowed depth of the same element in case of recursivity.
Option to be used in case of xs:choice or substitutionGroup. The possible strategies are:
First - the first branch of xs:choice or the head element of substitutionGroup will be always used;
Random - a random branch of xs:choice or a substitute element or the head element of a substitutionGroup will be used.
Option to generate the other possible choices or substitutions (for xs:choice and substitutionGroup). These alternatives will be generated inside comments groups so you can uncomment them and use later. Use this option with care (for example on a restricted namespace and element) as it may generate large result files.
The current settings can be saved for further usage with the Export settings button, and reloaded when necessary with the Load settings button.
The Element values tab allows you to add values that will be used to fill the content of elements. If there are more than one value, then the values will be used in a random order.
The Attribute values tab allows you to add values that will be used to fill the attributes. If there are more than one value, then the values will be used in a random order.
The XML instance generator tool can be used also from command line by running the
script called xmlGenerator.bat
(on Windows) /
xmlGenerator.sh
(on Mac OS X / Unix / Linux) located in the <oXygen/>
installation folder. The parameters can be set once in the dialog, exported to an XML
file on disk with the button "Export settings" and reused from command line. With the
exported settings file you can generate the same XML instances from the command line as
from the dialog:
xmlGenerator.sh -cfgFile myConfigurationFile.xml
The script can be integrated in an external batch process launched from the command line. The command line parameter of the script is the relative path to the exported XML settings file. The files which are specified with relative paths in the exported XML settings will be made absolute relative to the directory from where the script is run.
Example 4.11. Example of an XML configuration file saved with Export settings button
<settings> <schemaSystemId>http://www.w3.org/2001/XMLSchema.xsd</schemaSystemId> <documentRoot>schema</documentRoot> <outputFolder>D:\projects\output</outputFolder> <filenamePrefix>instance</filenamePrefix> <filenameExtension>xml</filenameExtension> <noOfInstances>1</noOfInstances> <openFirstInstance>true</openFirstInstance> <defaultNamespace><NO_NAMESPACE></defaultNamespace> <element namespace="<ANY>" name="<ANY>"> <generateOptionalElements>false</generateOptionalElements> <generateOptionalAttributes>false</generateOptionalAttributes> <valuesForContentType>DEFAULT</valuesForContentType> <preferredNumberOfRepetitions>2</preferredNumberOfRepetitions> <maximumRecursivityLevel>1</maximumRecursivityLevel> <choicesAndSubstitutions strategy="RANDOM" generateOthersAsComments="false"/> <attribute namespace="<ANY>" name="<ANY>"> <attributeValue>attrValue1</attributeValue> <attributeValue>attrValue2</attributeValue> </attribute> </element> <element namespace="<NO_NAMESPACE>" name="<ANY>"> <generateOptionalElements>true</generateOptionalElements> <generateOptionalAttributes>true</generateOptionalAttributes> <valuesForContentType>DEFAULT</valuesForContentType> <preferredNumberOfRepetitions>2</preferredNumberOfRepetitions> <maximumRecursivityLevel>1</maximumRecursivityLevel> <choicesAndSubstitutions strategy="RANDOM" generateOthersAsComments="true"/> <elementValue>value1</elementValue> <elementValue>value2</elementValue> <attribute namespace="<ANY>" name="<ANY>"> <attributeValue>attrValue1</attributeValue> <attributeValue>attrValue2</attributeValue> </attribute> </element> </settings>