Data Types in XML Data Schemas
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.
May 24, 2000
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 tag is the following:The "default" attribute specifies the default value for the attribute the node describes. Attributes such as dt:type and dt:values belong to the dt namespace and complete the description of the data type required for that attribute. Usually, you need to specify only the dt:type, which can be a value such as string, boolean, date, number, int, float, time. The "name" attribute contains a string that the parser interprets as a reference to the attribute itself. The "required" attribute can take one of two possible values ("yes" or "no".) And you can specify whether the attribute can be omitted. 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.
About the Author
You May Also Like