当前位置: 首页 > 网络学院 > XML相关教程 > Schema (XSD) > XSD 复合纯元素
An "elements-only" complex type contains an element that contains only other elements.
“ 纯元素(Elements-only)” 的复合类型包含了一个只包含其它元素的元素。
An XML element, "person", that contains only other elements:
一个XML元素"person"只含有其它元素:
<person> |
You can define the "person" element in a schema, like this:
你可以在一篇schema里定义"person"元素,如下所示:
<xs:element name="person"> |
Notice the <xs:sequence> tag. It means that the elements defined ("firstname" and "lastname") must appear in that order inside a "person" element.
请注意<xs:sequence>标签。这表示所定义的元素("firstname" 和 "lastname")必须在"person"元素里以<xs:sequence>标签定义的次序出现。
Or you can give the complexType element a name, and let the "person" element have a type attribute that refers to the name of the complexType (if you use this method, several elements can refer to the same complex type):
或者,你可以为complexType元素定义一个名称,让"person"元素包含一个类型属性,该类型属性的名称可以引用complexType元素的名称(如果你用上述方法,几个元素可以同时引用相同的复合类型):
<xs:element name="person" type="persontype"/> <xs:complexType name="persontype"> |