2012-07-30 172 views
3

元素定義自封閉的XML元素我想定義:我怎樣才能在一個XML Schema

<feature_ref id="0"/> 

代碼中,我把我的XSD文件:

<xs:attribute name="id" type="xs:integer"/>  
<xs:element name="feature_ref" type="xs:string"> 
    <xs:complexType> 
    <xs:attribute ref="id"/> 
    </xs:complexType> 
</xs:element> 

是否有辦法我可以在我的XSD中指定此元素應該自閉合?

回答

5

自閉元素是具有相同值的合成糖。出於同樣的原因,您無法控制屬性的順序或屬性之間的空白,因此無法使用XSD定義自動關閉。

換句話說:

<feature_ref id="0"/> 

是完全相同

<feature_ref id="0"></feature_ref> 

見W3規格:http://www.w3.org/TR/REC-xml/#sec-starttags