开发者

Is this the proper way to added enumerated attributes to a complexType?

Is this the proper way to set an attribute with enumerated values on the complexType AvailStatusMessageType. I see a lot of examples that declare a complexContent section right below the complexType declaration? What is this complexContent for and is it necessary here?

<xs:complexType name="AvailStatusMessageType">
    <xs:seque开发者_Python百科nce>
    <xs:element name="LengthsOfStay" type="LengthsOfStayType" />
    <xs:element name="RestrictionStatus" type="RestrictionStatusType"/>
</xs:sequence>
<xs:attribute name="BookingLimit">
<xs:simpleType>
    <xs:restriction base="xs:string">
        <xs:enumeration value="SetLimit" />
        <xs:enumeration value="AdjustLimit"/>
        <xs:enumeration value="RemoveLimit"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>


Element types can be divided into two categories in XML Schemas

  1. Elements that can contain structural markup (attributes or child elements)
  2. Elements that contain only textual markup

Further, the elements that contain markup (group 1) can be again divided to two groups

  1. Elements that are allowed to have child elements
  2. Elements that are not allowed to have child elements

First division separates (1) <complexType> and (2) <simpleType>. Second one separates (1) <complexContent> and (2) <simpleContent>.

<xs:complexContent> is not usually seen, because it is an implicit default so the whole structure can be abbreviated by omitting that element. This common structure

<xs:complexType>
  ... (<xs:sequence> or anything) ...
</xs:complexType>

is actually identical to

<xs:complexType>
  <xs:complexContent>
    <xs:restriction base="xs:anyType">
      ... (<xs:sequence> or anything) ...
    </xs:restriction>
  </xs:complexContent>
</xs:complexType>

In your structure an element with type "AvailStatusMessageType" 1) contains markup 2) and has child elements. So your structure is a complex type with complex content. Your example seems correct even though you haven't used the <xs:complexContent> element, because you are actually using the abbreviated form. It is identical to this:

<xs:complexType name="AvailStatusMessageType">
    <xs:complexContent>
        <xs:restriction base="xs:anyType">
            <xs:sequence>
                <xs:element name="LengthsOfStay" type="LengthsOfStayType" />
                <xs:element name="RestrictionStatus" type="RestrictionStatusType"/>
            </xs:sequence>
            <xs:attribute name="BookingLimit">
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:enumeration value="SetLimit" />
                        <xs:enumeration value="AdjustLimit"/>
                        <xs:enumeration value="RemoveLimit"/>
                    </xs:restriction>
                </xs:simpleType>
            </xs:attribute>
        </xs:restriction>
    </xs:complexContent>
</xs:complexType>


A complex type may have simple or complex content. You would use <simpleContent> if you were defining a complex type with simple content. You must use the <complexContent> element when you are restricting or extending another complex type (because you specify the base type as an attribute in the <complexContent> element). If you are simply creating a complex type (with complex content), as you are doing, you may use (but are not required to use) the <complexContent> element.

Your enumeration looks right.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜