As an XML developer, you'll want to choose a data-definition language that offers flexibility by letting you handle different data types. Although a Document Type Definition (DTD) lets you define each element attribute's name, a key advantage of an XML Data Schema (XDS) is that it lets you specify a data type for both elements and attributes. When you assign a data type to an attribute, you specify the data format and enable another level of validation and control for the XML parser or the client application that consumes the XML data through the XML Document Object Model (XMLDOM).
An XDS can contain two categories of data types. Along with the common data types that you find in all programming languages (string, date, integer), you can have any of the special data types included in the XML Language Specification, such as ID, IDREF, and NMTOKEN. A complete list of the XML data types is available on the Microsoft Developer Network (MSDN) in the XML Data Types Reference area. In addition, the XML 1.0 Recommendation from W3C—the consortium that governs XML technology—describes XML primitive types in Section 3.3.1.
If users access your application through Microsoft Internet Explorer (IE) 5.0 and later, an XDS needs to import the data type's (dt's) namespace to use the data type support. The schema declaration in the XML document would look like this:
In an XDS, attributes can appear in any order within an element, but each attribute can appear only once. Each attribute holds at least a name and a type:
However, the full syntax for the
The "default" attribute specifies the default value for the attribute the
You can also choose enumerations as your data type. In this case, the syntax would look like this:
You need to list the possible values for the enumeration and separate each by a letter space. The Microsoft XMLDOM available with IE 5.0 lets you access the content of a typed attribute. You can read that value as normal text or as a typed value. You use the nodeValue property in the former case, and you use the nodeTypedValue property in the latter case.