11.1. An Example of a Complex Type Specifying Empty Content

A complex type can specify empty content. In other words, an XML instance that contains an element that is an instance of an element type whose structure type is this complex type does not contain any text or any other elements. The freePriceType complex type presented in Listing 11.1 is used to “price” items in the catalog that have no cost associated with them. Any discount catalog item has an authorization attribute. The complex type freePriceType has no content (that is, no base simple type or nested element types):

Listing 11.1. A Complex Type Specifying Empty Content (pricing.xsd)
<xsd:complexType name="freePriceType" 
                 block="#all" 
                 final="#all" 
                 id="freePriceType.pricing.cType"> 
    <xsd:annotation> 
        <xsd:documentation xml:lang="en"> 
            Anything that is free has no 
            value (i.e., price), but must 
            have an authorization code. 
            This is a complex type with 
            "empty" content. 
                -- Shorthand Notation --
        </xsd:documentation> 
    </xsd:annotation> 
    <xsd:attributeGroup ref="saleAttributeGroup"/> 
</xsd:complexType>  
<xsd:attributeGroup name="saleAttributeGroup"> 
    <xsd:annotation> 
        <xsd:documentation xml:lang="en"> 
            Anything that is on sale (or free, 
            which is a type of sale), must 
            have an authorization defined. 
            This is someone's name, 
            initials, ID, etc. 
        </xsd:documentation> 
    </xsd:annotation> 
    <xsd:attribute name="authorization" type="xsd:token"/> 
</xsd:attributeGroup> 

An element type whose structure type is freePriceType might look like the following element:

<xsd:element name="freePrice" type="freePriceType"/> 

Given the preceding element type, the following element is valid in an XML instance:

<freePrice authorization="CB"/> 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.135.224