当前位置: 首页 > 网络学院 > XML相关教程 > Schema (XSD) > XML Schema complexType 元素

Schema (XSD)
XSD 逻辑值数据类型
XML Schema总结
XML Schema 参考
XSD 验证

Schema (XSD) 中的 XML Schema complexType 元素


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 432 ::
收藏到网摘: n/a

Definition and Usage
定义和用法

The complexType element defines a complex type. A complex type element is an XML element that contains other elements and/or attributes.
complexType元素的作用是:定义一个复合类型元素(complex type element)。复合类型元素包含了元素和/或属性。

Element Information
元素信息

  • Parent elements: element, redefine, schema
    父类元素:element[元素]、redefine[重定义]、schema

Syntax
语法

<complexType
id=ID
name=NCName
abstract=true|false
mixed=true|false
block=(#all|list of (extension|restriction))
final=(#all|list of (extension|restriction))
any attributes
>
(annotation?,(simpleContent|complexContent|((group|all|
choice|sequence)?,((attribute|attributeGroup)*,anyAttribute?))))
</complexType>

(The ? sign declares that the element can occur zero or one time, and the * sign declares that the element can occur zero or more times inside the complexType element)
“?”符号用于声明元素可以出现的次数(0次或1次),“*”符号用于声明元素可以在complexType元素中出现的次数(0次或多次)。

属性 描述
id Optional. Specifies a unique ID for the element
可选参数。为元素指定一个独立的ID
name Optional. Specifies a name for the element
可选参数。为元素指定一个名称
abstract Optional. Specifies whether the complex type can be used in an instance document. True indicates that an element cannot use this complex type directly but must use a complex type derived from this complex type. Default is false
可选参数。指定复合类型是否允许在实例文档中使用。True表示元素不能直接使用这个复合类型,但必须使用一个源于该复合类型的类型。默认值为:False
mixed Optional. Specifies whether character data is allowed to appear between the child elements of this complexType element. Default is false. If a simpleContent element is a child element, the mixed attribute is not allowed!
可选参数。指定是否允许字符数据在complexType元素的子元素中出现。默认值为false[假]。如果simpleContent元素不是一个子元素,那么不允许使用mixed属性
block

Optional. Prevents a complex type that has a specified type of derivation from being used in place of this complex type. This value can contain #all or a list that is a subset of extension or restriction:

可选参数。禁止一个包含指定来历类型的复合类型替代这个类型使用。该值包含了#all或一个扩展类型(或限制类型)的列表:

  • extension - prevents complex types derived by extension
    扩展类型 - 禁止用扩展类型中的复合类型
  • restriction - prevents complex types derived by restriction
    限制类型 - 禁止使用限制类型中的复合类型
  • #all - prevents all derived complex types
    #all - 禁止使用上述两种类型的复合类型
final

Optional. Prevents a specified type of derivation of this complex type element. Can contain #all or a list that is a subset of extension or restriction.

可选参数。禁止使用该复合类型元素中的类型。该值包含了#all或一个扩展类型(或限制类型)的列表:

  • extension - prevents complex types derived by extension
    扩展类型 - 禁止使用扩展类型中的复合类型
  • restriction - prevents complex types derived by restriction
    限制类型 - 禁止使用限制类型中的复合类型
  • #all - prevents all derived complex types
    #all - 禁止使用上述两种类型的复合类型
any attributes Optional. Specifies any other attributes with non-schema namespace
可选参数。指定非schema命名空间的其它属性

Example 1
案例1

The following example has an element named "note" that is of a complex type:
下面的案例包含名为“note”的元素,它是一个复合类型:

<xs:element name="note"> <xs:complexType> <xs:sequence>	<xs:element name="to" type="xs:string"/>	<xs:element name="from" type="xs:string"/>	<xs:element name="heading" type="xs:string"/>	<xs:element name="body" type="xs:string"/> </xs:sequence> </xs:complexType>
</xs:element>

Example 2
案例2

The following example has a complex type, "fullpersoninfo", that derives from another complex type, "personinfo", by extending the inherited type with three additional elements (address, city and country):
下面的案例中包含一个符合类型“fullpersoninfo”,它源于另外一个符合类型“personinfo”,通过扩展了另外三个元素(address、city、country)的继承类型:

<xs:element name="employee" type="fullpersoninfo"/>
<xs:complexType name="personinfo"> <xs:sequence> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/> </xs:sequence>
</xs:complexType>
<xs:complexType name="fullpersoninfo"> <xs:complexContent> <xs:extension base="personinfo"> <xs:sequence> <xs:element name="address" type="xs:string"/> <xs:element name="city" type="xs:string"/> <xs:element name="country" type="xs:string"/> </xs:sequence> </xs:extension> </xs:complexContent>
</xs:complexType>

In the example above the "employee" element must contain, in sequence, the following elements: "firstname", "lastname", "address", "city", and "country".
在上述案例中,“employee”元素必须按顺序包含下列元素:"firstname"、"lastname"、"address"、"city"和"country"。

评论 (0) All

登陆 | 还没注册?