(1) You could avoid defining a named xs:complexType
:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="myEmptyElement">
<xs:complexType/>
</xs:element>
</xs:schema>
(2) You could use a xs:simpleType
instead of a xs:complexType
:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="myEmptyElement">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="0"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:schema>
(3) You could use fixed=""
[credit: @Nemo]:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="myEmptyElement" type="xs:string" fixed=""/>
</xs:schema>
(4) But note that if you avoid saying anything about the content model:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="myEmptyElement"/>
</xs:schema>
You'll be allowing any attributes on and any content in myEmptyElement
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…