XML Tutorial/XML Schema/fixed

Материал из Web эксперт
Перейти к: навигация, поиск

Predefining an Element"s Content with a fixed value or default value.

   <source lang="xml">

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.wbex.ru" 
 xmlns="http://www.wbex.ru"
 elementFormDefault="qualified">
 <xsd:element name="status" type="xsd:string" fixed="endangered" />

</xsd:schema>

File: Data.xml <?xml version="1.0"?> <status xmlns="http://www.wbex.ru">endangered</status></source>