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

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

Schema (XSD) 中的 XML Schema extension 元素


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

Definition and Usage
定义和用法

The extension element extends an existing simpleType or complexType element.
extension元素的作用是:扩展一个现有的simpleType[简单类型]元素或complexType[复合类型]元素。

Element Information
元素信息

  • Parent elements: simpleContent, complexContent
    父类元素:simpleContent[简单内容]、complexContent[复合内容]

Syntax
语法

<extension
id=ID
base=QName
any attributes
>
(annotation?,((group|all|choice|sequence)?,
((attribute|attributeGroup)*,anyAttribute?)))
</extension>

(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 extension element)
“?”符号用于声明元素可以出现的次数(0次或1次),“*”符号用于声明元素可以在extension元素中出现的次数(0次或多次)。

属性 描述
id Optional. Specifies a unique ID for the element
可选参数。为元素指定一个独立的ID
base Required. Specifies the name of a built-in data type, a simpleType element, or a complexType element
必要参数。指定一个内置数据类型、一个simplleType[简单类型]元素或是一个complexType[复合类型]元素的名称
any attributes Optional. Specifies any other attributes with non-schema namespace
可选参数。指定非schema命名空间的其它属性

Example 1
案例1

The following example extends an existing simpleType by adding an attribute:
下面的案例中通过添加一个属性扩展了现有的simpleType[简单类型]元素:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="size"> <xs:restriction base="xs:string"> <xs:enumeration value="small" /> <xs:enumeration value="medium" /> <xs:enumeration value="large" /> </xs:restriction>
</xs:simpleType>
<xs:complexType name="jeans"> <xs:simpleContent> <xs:extension base="size"> <xs:attribute name="sex"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="male" /> <xs:enumeration value="female" /> </xs:restriction> </xs:simpleType> </xs:attribute> </xs:extension> </xs:simpleContent>
</xs:complexType>
</xs:schema>

Example 2
案例2

The following example extends an existing complexType element by adding three elements:
下面的案例中通过添加三个元素扩展了现有的complexType[复合类型]元素:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<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>
</xs:schema>

评论 (0) All

登陆 | 还没注册?