An "elements-only" complex type contains an element that contains only other elements.
“只有元素(Elements-only)”复合类型含有一个只包含其他元素的元素
Complex Types Containing Elements Only
复合类型只含有元素
An XML element, "person", that contains only other elements:
一个XML元素, "person",只含有其他元素:
<person> <firstname>John</firstname> <lastname>Smith</lastname> </person> |
You can define the "person" element in a schema, like this:
你可以在一篇schema里定义"person"元素,就像这样
<xs:element name="person"> <xs:complexType> <xs:sequence> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> |
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"元素里以那样的次序出现。
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"> <xs:sequence> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/> </xs:sequence> </xs:complexType> |