XML

Simple Schema Data Types

For the most part, XML documents fall into two categories: document-oriented and data-oriented. The document-oriented XML document contains text sections mixed with field data, whereas the data-oriented XML document contains only field data. The XHTML document we created in Chapter 5 is an example of a document-oriented XML document. Another example of a document-oriented XML document is a message such as the one shown here:

  <message priority="high"
      date="2000-01-11">
      <from>Jake Sturm</from>
      <to>Gwen Sturm</to>
      <subject>DNA Course</subject>
      <body>
          The new DNA course that we are offering is now complete.
          It will provide a complete overview discussion of
          designing and building DNA systems, including DNS, DNA,
          COM, and COM+. The course is also listed on the Web site, at
          http://ies.gti.net.
      </body>
  </message>

This message has a large text body, but it also contains attributes-in this case, date and priority. The date attribute has a date data type, and the priority attribute has an enumerated data type. It will be useful to be able to validate that these attributes are correctly formatted for these two data types. Schemas will allow you do this.

A data-oriented document looks like this:

  <bill>
      <OrderDate>2001-02-11</OrderDate>
      <ShipDate>2001-02-12</ShipDate>
      <BillingAddress>
          <name>John Doe</name>
          <street>123 Main St.</street>
          <city>Anytown</city>
          <state>NY</state>
          <zip>12345-0000</zip>
      </BillingAddress>
      <voice>555-1234</voice>
      <fax>555-5678</fax>
  </bill>

This entire document contains data fields that will need to be validated. Validating data fields is an essential aspect of this type of XML document. We'll look at an example schema for a data-oriented document in the section "A Schema for a Data-Oriented XML Document" later in this chapter.

Up to this point, we've been looking only at document-oriented XML documents that contain only one data type (the string data type) because DTDs work best with document-oriented XML documents that contain only string data types. Because schemas allow you to validate datatype information, it's time now to take a look at data types as they are defined in the schema specification.

The term data type is defined in the second schema standard, which can be found at http://www.w3.org/TR/xmlschema-2/. A data type represents a type of data, such as a string, an integer, and so on. The second schema standard defines simple data types in detail, and that's what we'll look at in this section.

by BrainBellupdated
Advertisement: