Editing and Validating XML Document Example Readme

This is a collection of examples that illustrate how you can use some of the guided editing features in the XML Editor to edit and validate XML files.
 
Example Description
Invoice Shows how a DTD file (Invoice.dtd) can be used to provide editing assistance when editing an XML file (Invoice.xml).
PublicationCatalogue This example shows how to define substitutionGroup in an XML schema file and then use the substitution in the XML instance document.
GolfCountryClub This example defines an XML schema of a Golf Country Club. It demonstrates the use of enumerations, local types, choices, and extensions to extend complex types (inheritance).


Editing Invoice.xml

The Invoice.dtd file provides the rules for defining the content of the Invoice.xml file. It is associated with the Invoice.xml through the DOCTYPE declaration.

Sequence content model

The Invoice element has a content model that looks like this:
    <ELEMENT Invoice (Header, Items+)>
This means that an Invoice element can have one Header element followed by multiple Items.

In the Design View of the XML Editor, select the Invoice element. From the pop-up menu, select Add Child -> Item to add an Item to the Invoice element. You can repeat this to add as many Items to the Invoiceelement as you like.

Choice content model

The Date element has a content model that looks like this:
    <ELEMENT Date ((Month, Day, Year) | (Day, Month, Year))>
This means that a Date can be of the format Month, followed by Day, followed by Year, or of the format Day, followed by Month, followed by Year.

You can toggle between these two groups easily in the Design View of the XML Editor: First multiple select the Month, Day, and Year elements (Hold down the Ctrl key while you select them). Then from the pop-up menu, choose Replace With -> (Day, Month, Year) to replace it with the second group.

Enumerated attribute type

The Item element has an attribute discount whose value can be set to either promotion or regular. In the Design View of the XML Editor, select the discount attribute. A combo-box will appear where you can choose between the two values. Alternatively, in the Source View, select content assist for the discount attribute to choose between the two values.



Using Substitution Groups

XML Schema allows named groups of elements to be substituted for other elements. The Catalogue.xsd file declares Book and Magazine to be in a substitution group with Publication:

    <element name="Book" type="Catalogue:BookType" substitutionGroup="Catalogue:Publication"/>
    <element name="Magazine" type="Catalogue:MagazineType" substitutionGroup="Catalogue:Publication"/>
The content of Catalogue can be any element that is in the substitution group. In the Design View of the XML Editor, select the Add Child menu on the Catalogue element. Notice how both Book and Magazine can be substituted as the content of the Publication element. In additon, we have declared the Publication element as abstract, to prevent the Publication element to be used directly in the instance document..
 


XML Schema - Golf Country Club Example

Inheritance

The GolfCountryClub.xsd defines various types that extend content from other complex types. In particular, look at the various member types and EmployeeType, and they all extend PersonType.

Enumerations

You can restrict the values allowed for an element in the instance document by defining enumerations in the schema. For example, look at the simple type ClubKindType in the schema. Then, look at ClubKind element in the instance document, GolfCountryClub.xml, using the XML Editor.

Choices

Similar to the Invoice example, you can choose a different content model for a particular element. In the golf country club example, a Member can be restricted, regular or exclusive.