Mega Code Archive

 
Categories / XML Tutorial / XML Schema
 

Default and Fixed Values

In XML Schemas, you can declare  default and fixed values  for elements as well as attributes.  When declaring default values for elements, you can specify only a text value.  To specify a default value, simply include the default attribute with the desired value.  <element name="last" type="string" default="Doe"/>  <last></last> or <last/> then it would treat the element as: <last>Doe</last>  If the element does not appear within the document or if the element already has content,  then the default value is not used.  When an element's value can never change, simply include a fixedattribute with the fixed value.  <element name="version" type="string" fixed="1.0"/>