Important concepts in XSD properties and types
There are some important distinctions to make in terminology when understanding how Gosu creates types from XSDs. In the following table, note how every definition in the XSD has a corresponding instance in an XML document (although in some cases might be optional).
Definitions in the XSD |
Instances in an XML document |
|---|---|
A schema (an XSD) |
XML document |
Element definition |
Element instance |
Complex type definition |
Complex type instance |
Simple type definition |
Simple type instance |
Attribute definition |
Attribute instance |
For every element definition in the XSD:
- There is an associated type definition.
- The type definition is either a complex type definition or simple type definition.
- The element definition has one of the following qualities:
- It references a top-level type definition, such as a top-level complex type.
- It embeds a type definition inside the element definition, such as an embedded simple type.
- It includes no type, which implicitly
refers to the built-in complex type
<xsd:anyType>.
In an XSD, various definitions cause Gosu to create new types:
- An element definition causes Gosu to create a type that describes the element.
- A type definition causes Gosu to create a type that describes the type (for example, a new complex type).
- An attribute definition causes Gosu to create a type that describes the attribute.
For example, suppose an XSD declares a new top-level simple type that represents a phone number. Suppose there are three element definitions that reference this new simple type in different contexts for phone numbers, such as work number, home numbers, and cell number. In this example, Gosu creates:
- One type that represents the phone-number simple type.
- Three types that represent the individual element definitions that reference the phone number.
From Gosu, whenever you create objects or set properties on elements, you need to know which type to use. In some cases, you can do what you need in more than one way, so consider using the most readable technique.
If you have a reference to the element,
you can always reference the backing type. For example, for an element,
you can reference the backing type instance using the $TypeInstance property.
See also
