October 06, 2003
XML Schema Terminology
Making sense of XML Schema (XS) terminology is like shitting a bowling ball. Here's some help.
General Terminology Guidelines
- Type refers to everything about an Element or Attribute, whereas Content only refers to what's in between the opening and closing tag of Elements. In other words, unlike Type, Content describes an Element's child Elements or Text or the fact that the Element is Empty; it does not cover whether the Element has Attributes or not.
- A Simple Element is an Element that only contains Text, whereas a Complex Element is any other type of Element, i.e. an Element that is Empty, or has Attributes, or has child Elements, or any combination of the above and/or Text.
- When one talks of Simple Elements or Complex Elements, one means Elements of Simple Type and Elements of Complex Type. Note that by itself, the term Simple Type could be applied to Elements or Attributes.
Terminology
- Simple Element and Simple Type
Definition: a Simple Element is an XML Element that can only contain Text, but not Child Elements nor Attributes.
E.g.: XML: <dateborn>1968-03-27</dateborn>
XS: <xs:element name="dateborn" type="xs:date" />
NOTE: for an Element to only contain Text, its type has to be either a pre-defined XML Schema datatype or a custom Simple Type (see next definition).
- Custom Simple Type for an Element or Attribute
Definition: A Custom Simple Type is a new Simple Type based on a List of values or on a Restriction or Union of Simple Type(s). This or these base Simple Types can be pre-defined XML Schema datatypse or some other Custom Simple Types. The XS element xs:simpleType comes into play when you create a new Simple Type.
E.g.: XML: <age>100</age>
XS: <xs:element name="age">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="100"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
- Complex Element and Complex Type
Definition: A Complex Element is any XML Element that cannot be considered a Simple Element. There are 4 types of Complex Elements.
- Complex Empty Element
Definition: Element that has null Content (but can optionally have Attributes)
E.g.: XML: <product pid="1345"/>
XS: <xs:element name="product">
<xs:complexType>
<xs:attribute name="prodid" type="xs:positiveInteger"/>
</xs:complexType>
</xs:element>
NOTE: Contrast with <xs:element name="product"/>, which counter-intuitively does not specify an Empty Element; it specifies an Element of any Type and any Content.
- Complex Elements-Only Element
Definition: Element that can contain only other Elements (and optionally Attributes)
E.g.: XML: <employee>
<firstname>John</firstname>
<lastname>Smith</lastname>
</employee>
XS: <xs:element name="employee">
<xs:complexType>
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- Complex Mixed-Content Element
Definition: Element that can contain Elements and Text (and optionally Attributes)
E.g.: XML: <letter>
Dear Mr.<name>John Smith</name>.
Your order <orderid>1032</orderid>
will be shipped on <shipdate>2001-07-13</shipdate>.
</letter>
XS: <xs:element name="letter">
<xs:complexType mixed="true">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="orderid" type="xs:positiveInteger"/>
<xs:element name="shipdate" type="xs:date"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- Complex Text-Only Element
Definition: Element that can only contain Text (and optionally Attributes).
E.g.: XML: <shoesize country="france">35</shoesize>
XS: <xs:element name="shoesize">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:integer">
<xs:attribute name="country" type="xs:string" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
Note: This specifies an Element of Complex Type and Simple Content. Because it can contain Attributes, the Element is of Complex Type. But because it does not contain other elements, it is of Simple Content.
Note: It follows, then, that if there are no Attributes, you might as well use a Simple Type, which would be equivalent.
Note: The XS syntax inside xs:simpleContent is like that of xs:simpleType in that you need to declare a xs:restriction/xs:union/xs:list Element inside, but unlike xs:simpleType, you can also declare an xs:extension Element inside so that Attributes may be defined.
Note: If you want to both restrict the Type of the Text (xs:restriction) and also add an Attribute (xs:extension), you're going to have to separately define an intermediary (xs:restriction) Simple Type that you would then use as base for your xs:simpleContent's xs:extension.
- Complex Content
Definition: Note that there isn't a one-to-one relationship between "Complex Elements" and "Elements with Complex Content". Complex Content refers to what can be specified inside the opening and closing tags of the first 3 of the 4 Complex Elements defined above; Complex Text-Only Element is the exception.
Posted by juliob at October 06, 2003 03:36 AM
Thank you for putting this out on the web. You really helped to clear up some confusion that my textbook was unable to make clear.
License: