Specifying Default Values for Elements

In addition to the minOccurs and maxOccurs attributes, you can use the <xsd:element> element's fixed and default attributes to indicate values that an element must have (you use one of these attributes, not both together). For example, setting fixed to 400 means that the element's value must always be 400 . Setting the default value to 400 , on the other hand, means that the default value for the element is 400 , but if the element appears in the document, its actual value is the value it encloses.

For example, here I'm setting the value of an element named <maxTrials> to 100 and specifying that it must always be 100 , using the fixed attribute in the <xsd:element> element:

 <xsd:element name="maxTrials" type="xsd:integer" fixed="100"/> 

And here I'm giving this element the default value of 100 instead of fixing its value at 100 :

 <xsd:element name="maxTrials" type="xsd:integer" default="100"/> 


Real World XML
Real World XML (2nd Edition)
ISBN: 0735712867
EAN: 2147483647
Year: 2005
Pages: 440
Authors: Steve Holzner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net