Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I define a self closing XML element in an XML Schema

Tags:

xml

xsd

Element I want to define:

<feature_ref id="0"/>

Code I've put in my XSD file:

<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>

Is there a way I can specify in my XSD that this element should be self-closing?

like image 498
Max Hartshorn Avatar asked Jul 30 '12 21:07

Max Hartshorn


1 Answers

Self-closing elements are syntaxic sugar for the same value. For the same reason you cannot control the sequence of attributes, or the whitespace between attributes, self-closing cannot be defined with XSD.

In other words:

<feature_ref id="0"/>

is exactly the same as

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

See the W3 specifications: http://www.w3.org/TR/REC-xml/#sec-starttags

like image 95
Christian Rondeau Avatar answered Oct 16 '22 13:10

Christian Rondeau