XML Schema Properties
All attributes are declared as simple types.
What is an attribute?
Simple elements can not have attributes. If an element has attributes, it will be treated as some kind of complex type. But the property itself is always used as a simple type declaration.
How to declare property?
The syntax is defined properties
Here, xxx is the property name, yyy provides that the data type of the attribute. XML Schema has a lot of built-in data types.
The most common types are:
- xs: string
- xs: decimal
- xs: integer
- xs: boolean
- xs: date
- xs: time
Examples
This is the XML elements with attributes:
This is the corresponding attribute definition:
The default value and the fixed value of the property
Property has a specified default value or a fixed value.
When no other value is specified, the default value is automatically assigned to the element.
In the following example, the default value is "EN":
Fixed values are also automatically assigned to the elements, and you can not predetermined additional value.
In the following example, the fixed value is "EN":
Optional and required attributes
In case of default, the attribute is optional. To specify attributes is required, please use the "use" attribute:
Defining the content
When an XML element or attribute has a data type is defined, it will add to the content defining element or attribute.
If the type of XML element is "xs: date", and the content it contains is similar to "Hello World" string element will not (through) authentication.
Through XML schema, you can also add your own to define your XML elements and attributes. These limits are called facet (Editor's note: meaning (polyhedron) surface, can be translated as defined surface). You will learn more about the facet of knowledge in the following section.