Mega Code Archive

 
Categories / XML Tutorial / XML Schema
 

Predefining an Elements Content with a fixed value or default value

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.rntsoft.com"    xmlns="http://www.rntsoft.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.rntsoft.com">endangered</status>