Quantcast

XSchema Attributes and Restriction

In a previous article, we discussed about XSchema, its implications and also its elements. In this article, we would be discussing its attributes and the restrictions that are faced while scripting with XSchema.

First, let’s take a look at XSchema attributes. Simple elements cannot have attributes. If an element has attributes, it is considered to be of a complex type. But the attribute itself is always declared as a simple type.

Where xxx is the name of the attribute and yyy specifies the data type of the attribute.

Attributes may have a default value OR a fixed value specified. A default value is automatically assigned to the attribute when no other value is specified. In the following example the default value is “EN”:

A fixed value is also automatically assigned to the attribute, and you cannot specify another value. In the following example the fixed value is “EN”:


Attributes are optional by default. To specify that the attribute is required, use the “use” attribute:

Now, let’s take a look at XSchema restrictions. When an XML element or attribute has a data type defined, it puts restrictions on the element’s or attribute’s content. If an XML element is of type “xs:date” and contains a string like “Hello World”, the element will not validate. The following example defines an element called “age” with a restriction. The value of age cannot be lower than 0 or greater than 120:

To limit the content of an XML element to a set of acceptable values, we would use the enumeration constraint. The example below defines an element called “car” with a restriction. The only acceptable values are: Audi, Golf, BMW:

To limit the content of an XML element to define a series of numbers or letters that can be used, we would use the pattern constraint. The example below defines an element called “letter” with a restriction. The only acceptable value is ONE of the LOWERCASE letters from a to z:

There are several other important XSchem restriction which we would discuss in a future article reserved for XSchema restrictions.

Looking for a quality hosting service? here are a few I suggest.
BlueHost | HostGator | Media Temple
Admin
Admin
Ali has been an entrepreneur in web, video and related technologies. Having worked with many business across the globe, Ali stands truly a great pillar in the business working with him.