Mega Code Archive

 
Categories / XML Tutorial / XML Schema
 

Defining Complex Types

An element that can contain other elements or that is allowed to contain attributes is a complex type. There are four kinds of elements of complex type:  "element only" contain just other elements or attributes-but no text,  "empty" elements contain attributes-but never elements or text,  "mixed content" elements contain a combination of elements, attributes, and/or text-especially elements and text,  "text only" elements contain only text-and possibly attributes. Within <complexType> definitions, you can specify the allowable element content for the declaration:  When we created a local declaration, we did not include a name attribute in our <complexType> definition.  Local <complexType> definitions are not named, which are called anonymous complex types.  Global <complexType> definitions are always named, so that they can be identified later.  <complexType> definitions can also be used to create mixed and empty content models.  Mixed content models allow you to include both text and element content within a single content model.  <element name="description">      <complexType mixed="true">          <choice minOccurs="0" maxOccurs="unbounded">              <element name="em" type="string"/>              <element name="strong" type="string"/>              <element name="br" type="string"/>          </choice>      </complexType>  </element>