当前位置: 首页 > 网络学院 > XML相关教程 > Schema (XSD) > XSD 复合空元素
An empty complex element cannot have contents, only attributes.
一个空的复合元素不能包含内容,只能包含属性。
An empty XML element:
一个空的XML元素如下:
<product prodid="1345" /> |
The "product" element above has no content at all. To define a type with no content, we must define a type that allows only elements in its content, but we do not actually declare any elements, like this:
上述"product"元素完全不包含任何内容。为了定义不包含内容的类型,我们必须定义一个内容中只允许出现元素的类型。但是,我们不需要声明任何元素,如下所示:
<xs:element name="product"> |
In the example above, we define a complex type with a complex content. The complexContent element signals that we intend to restrict or extend the content model of a complex type, and the restriction of integer declares one attribute but does not introduce any element content.
在上述案例中,我们定义了一个包含复合内容的复合类型。复合内容的元素指明了我们想要约束或扩充的复合类型的内容模式,并对整数的约束条件声明了一个属性,但不包含对元素内容的介绍。
However, it is possible to declare the "product" element more compactly, like this:
然而,我们还可以更加简洁地声明"product"元素,如下所示:
<xs:element name="product"> |
Or you can give the complexType element a name, and let the "product" 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元素起个名称,并使"product"元素包含一个类型属性,并且,类型属性引用的是complexType的名称(如果你使用这个方法,那么,几个元素就可以引用相同的复合类型):
<xs:element name="product" type="prodtype"/> <xs:complexType name="prodtype"> |