May 28, 2021 XML Schema
3. How do I declare a property?
4. The default and fixed values of the property
All properties are declared as simple types.
That is, elements with properties are always defined as composite types.
Simple elements cannot have properties. I f an element has a property, it is treated as a composite type. But the property itself is always declared as a simple type.
The syntax that defines the property is
Here, xxx refers to the property name, and yyy specifies the data type of the property. XML Schema has many built-in data types.
This is an XML element with properties:
This is the corresponding property definition:
The property can have a specified default or fixed value.
When no other values are specified, the default values are automatically assigned to the element.
In the following example, the default value is "EN":
Fixed values are also automatically assigned to elements, and you cannot specify additional values.
In the following example, the fixed value is "EN":
By default, properties are optional. To make the property mandatory, use the "use" property:
When an XML element or property has a defined data type, qualification is added to the contents of the element or property.
If the type of the XML element is "xs:date" and it contains a string similar to "Hello World," the element will not (pass) validation.
With XML schema, you can also add your own qualifications to your XML elements and properties. T hese qualifications are called facets (editor's note: meaning polyheddre faces, which can be translated as qualifiers). You'll learn more about facet in the next section.