Home

 

Generating an XML file from an XML schema

Rational Application Developer is capable of generating an XML document from an XML schema. This is useful because it allows a developer to gain familiarity with XML documents that are valid against a specific schema. In practice, a schema is used to validate XML documents created elsewhere. Also, an XML document generated from a schema is often called an XML instance document or simply an instance document. To generate an XML file from our XML schema file, follow these steps:

In the Enterprise Explorer, right-click Accounts.xsd and select Generate Æ XML File.

Accept the default name Accounts.xml. Click Next.

The XML schema you created earlier does not have optional attributes or elements. Accept the default values in the Select Root Element page (Create first choice of required choice, Fill elements and attributes with data). Click Finish.

The XML file opens in the editor.

Right-click the generated XML file Account.xml and select Validate. Notice the validation errors against AccountID, interest, and phoneNumber. The default values inserted by Rational Application Developer are not valid against the schema.

The XML schema specifies that the account id is 6 to 8 digits long. Change the account id to 123456.
Change the interest value to one which is valid (5.5).
Change the phone number to a valid (xxx) xxx-xxxx format, for example, (123) 456-7890.
Optionally change the firstName and lastName to your name.

Right-click Account.xml and select Validate. You should have no validation errors.
ibm.com/redbooks