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

Home
XML Tutorial
1.Introduction
2.Namespace
3.XML Schema
4.XPath
5.XSLT stylesheet
XML Tutorial » XML Schema » fixed 
3.88.1.Predefining an Element's 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.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.
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.