Schemas

[Previous] [Next]

Since the XML 1.0 Recommendation came out in February 1998, the W3C has been working on an alternative specification to replace the DTD for describing schemas. As I write this, the XML Schema work is in its final stages, and should be out as a Candidate Recommendation in the first half of 2000.

The W3C XML Schema Working Group is focusing on three improvement areas:

  • They want to see schemas written using XML syntax, thereby allowing us to use the same tools we use to process our XML documents.
  • They want the new schema standard to support common data types such as number, date, and currency, as well as user-defined data types. This kind of support would move the validation of the data from the application down to the XML parser, where data is accessible by all programs reading the XML document.
  • They want the XML Schema to have open content models. Think of our invoice that required flexible address information. An XML Schema would allow us to define one schema for the invoice information, with a "hole" for an address block. We could then use any schema that describes the required addressing convention and plug that schema into the invoice schema.

NOTE
The W3C is working on a specification called Datatypes for DTDs (DT4DTD) that will add data type support to the DTD. This is a patch to the DTD syntax, but will allow users who want to continue to use the DTD to have access to rich data types. Of course, XML parsers must support the standard for it to be useful.

The W3C schema has other features that are lacking in the DTD.

XML Data Reduced

Microsoft was an early proponent of XML and has been involved in the W3C's work on XML standards by submitting specifications for technical review or participating in the many XML-related committees. In January 1998, Microsoft, DataChannel, ArborText, and Inso submitted an alternative schema syntax called XML Data. This syntax achieved the three goals I listed at the end of the previous section, along with a couple of new items.

In December 1998, Microsoft released Internet Explorer 5, which shipped with a parser implemented as a COM object called MSXML. MSXML contains a reduced version of XML Data called XML Data Reduced, or XDR.

Since the W3C XML Schema Working Group is still working on their official schema, Microsoft recommended XDR as the schema syntax for BizTalk. Microsoft has, however, committed to implementing the W3C Schema syntax (dubbed XSD) once it is a final Recommendation.

Should you use XML Data knowing that a schema standard is months away? If you write applications using BizTalk and XML Data today, won't you have to rewrite those applications tomorrow? The answer is no. Microsoft and other vendors will provide tools to convert XDR syntax to XSD. Since the two syntaxes have identical goals, a machine translation of one syntax to another is trivial. Since all syntaxes are in XML syntax, XSL (the Extensible Stylesheet Language) can be used to convert from one schema syntax to another.

A tool available from Extensibility, Inc., named XML Authority (http://www.extensibility.com), also allows you to create and maintain schemas. With this product, you can create a schema in a graphical way without worrying about how the syntax will eventually look. I like the product because it stresses what is important, that is, defining a logical hierarchical representation of your data. The product can write to any of a number of schema syntaxes. It can even read one syntax and save as another. Figure 4-2 shows the tool in action.

You can also create an example of a well-formed document, and XML Authority will create a schema from it. It will also create schemas from COM objects, Java Classes, and ODBC data sources.

click to view at full size.

Figure 4-2. XML Authority, a tool from Extensibility, Inc.

The XML Data Reduced syntax is documented on the Microsoft XML Developer Center, http://msdn.microsoft.com/xml. Listing 4-5 shows an example XDR schema.

Listing 4-5. Sample XML Data Reduced (XDR) schema.

 Joke.xdr 1 <?xml version ="1.0"?> 2 <Schema name="Joke.xdr" 3 xmlns="urn:schemas-microsoft-com:xml-data" 4 xmlns:dt="urn:schemas-microsoft-com:datatypes"> 5 <ElementType name="joke" content="eltOnly" order="one"> 6 <AttributeType name="author" dt:type="string" 7 required="yes"/> 8 <AttributeType name="firstTold" dt:type="dateTime.tz"/> 9 <AttributeType name="rating" dt:type="enumeration" 10 dt:values="G PG R NC-17" required="yes"/> 11 <attribute type="author"/> 12 <attribute type="firstTold"/> 13 <attribute type="rating"/> 14 <element type="one-liner"/> 15 <element type="story"/> 16 <element type="setup-punchline"/> 17 </ElementType> 18 19 <ElementType name="one-liner" content="textOnly"/> 20 <ElementType name="story" content="eltOnly" order="seq"> 21 <element type="scene" minOccurs="1" maxOccurs="*"/> 22 </ElementType> 23 24 <ElementType name="setup-punchline" content="eltOnly" 25 order="seq"> 26 <element type="setup"/> 27 <element type="punchline"/> 28 </ElementType> 29 30 <ElementType name="scene" content="textOnly"/> 31 <ElementType name="setup" content="textOnly"/> 32 <ElementType name="punchline" content="textOnly"/> 33 </Schema> 

Table 4-1 describes the schema in Listing 4-5.

Line Description
1 The schema is an XML document.
2 The Schema start tag indicates the root element. The name of the schema is contained in the name attribute.
3-4 The XDR schema specification includes two namespaces: one for structures and the other that defines the datatypes used in the schema.
5-17 The ElementType element declares an element and indicates its contents. In this case, we are declaring the joke element. Attributes indicate that the joke element contains only elements (content="eltOnly"), and that this element can contain only one of the subelements listed (order="one").
6-7 Attributes are declared with the AttributeType element. Here, the author attribute is declared as having a string data type (dt:type="string"). When the joke element is started, the author attribute is required (required="yes").
8 The firstTold attribute is declared as containing a valid date. The dateTime.tz datatype is defined by the XDR specification as being a subset of the ISO 8601 standard for specifying date, time, and time zone. The syntax looks like this: 2000-04-25T09:00-08:00. It indicates 9:00 a.m. on April 25, 2000, offset 8 hours behind Greenwich Mean Time. The firstTold attribute is not required.
9-10 The rating attribute has a datatype of enumerated. That means it can only be one of a list of values indicated in the dt:values attribute. In this case, the value can only be "G", "PG", "R", or "NC-17". The rating attribute is required.
11-13 After attributes are declared for each element, they must be placed using the attribute element.
14-16 The element element indicates the elements that can be placed inside the joke element. Remember that the content attribute of the ElementType element indicated that only one of these three elements can be contained inside the parent element. Each one of these elements must be declared with its own ElementType element.
24-28 The setup-punchline element is declared here. The attribute, order="seq", indicates that the elements listed here must appear in the order in which they are placed in the declaration. The elements listed are setup and punchline. So in the document, the setup-punchline element must consist of a single setup element followed by a single punchline element.
30-32 The three elements here consist only of text.

Table 4-1. Description of the schema in Listing 4-5.

The W3C XML Schema Working Group continues to work on the XML Schema syntax. As of April 2000, Working Drafts of XML Schema Parts 1, 2, and 3 have been released. XML Schema provides a superset of the capabilities found in XML 1.0 DTDs. The BizTalk initiative uses XDR as its syntax for describing XML documents.

The main difference between XSD and XDR is the actual syntax of the schema documents. However, there really isn't a conceptual difference between the two. Microsoft has committed to implementing XSD as soon as it is available, either as a Candidate or final Recommendation.



XML and SOAP Programming for BizTalk Servers
XML and SOAP Programming for BizTalk(TM) Servers (DV-MPS Programming)
ISBN: 0735611262
EAN: 2147483647
Year: 2000
Pages: 150

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net