Predefining an Element's Content with a fixed value or default value. : fixed « XML Schema « XML Tutorial






The fixed attribute only sets the content if the element actually appears in the XML. 
If it is omitted, no content is set.
If the fixed attribute is set and the element is empty, the element's value is automatically set to the fixed value.


File: Schema.xsd 

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  targetNamespace="http://www.java2s.com" 
  xmlns="http://www.java2s.com"
  elementFormDefault="qualified">

  <xsd:element name="status" type="xsd:string" fixed="endangered" />


</xsd:schema>

 

File: Data.xml
<?xml version="1.0"?>
<status xmlns="http://www.java2s.com">endangered</status>








3.88.fixed
3.88.1.Predefining an Element's Content with a fixed value or default value.