All properties are declared as simple types. Simple elements cannot have attributes. If an element has an attribute, it is treated as a compound type. But the property itself is always declared as a simple type. The syntax for defining attributes is Here, xxx refers to the name of the attribute, and yyy specifies the data type of the attribute. XML Schema has many built-in data types. Xs:string Xs:decimal Xs:integer Xs:boolean Xs:date Xs:time This is the XML element with attributes: This is the corresponding attribute definition: Property can have a specified default value or 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 elements, and you cannot specify additional values. In the following example, the fixed value is “EN”: By default, properties are optional. To specify the attribute as required, use the “use” attribute: When an XML element or attribute has a defined data type, a qualification is added to the content of the element or attribute. If the XML element is of type “xs:date” and contains a string similar to “Hello World”, the element will not be validated. With XML schema, you can also add your own qualifications to your XML elements and attributes. These qualifiers are called facet. You’ll learn more about facet in the next section.What is an attribute? ¶
How do I declare properties? ¶
<xs:attribute name="xxx" type="yyy"/>
The most common types are: ¶
Example ¶
<lastname lang="EN">Smith</lastname>
<xs:attribute name="lang" type="xs:string"/>
Default value and fixed value of the attribute ¶
<xs:attribute name="lang" type="xs:string" default="EN"/>
<xs:attribute name="lang" type="xs:string" fixed="EN"/>
Optional and required properties ¶
<xs:attribute name="lang" type="xs:string" use="required"/>
Limitation of content ¶