3.6 Document Type Definitions (DTDs) vs. Schema/XSD

3.6 Document Type Definitions (DTDs) vs. Schema/XSD

A schema is a plan, map, diagram, or outline. The Document Type Definition is a schema, because XML processors use it to validate a document. If the document follows the rules or "map" of the DTD, the XML is valid. However, the World Wide Web Consortium recently approved the recommendation for creating and using XML Schema Documents (XSD). These rules are far more complex than for DTDs, but they also provide a broader range of information about the document and the markup, which defines the document contents.

The DTD provides a map to the structure of the XML document, but Document Type Definitions have limited rules to describe the document. Data types cannot be specified, so a number is just another piece of text. The data cannot be tested against validation rules, such as containing only uppercase letters or constraining the length of the data field to two characters. The schema recommendation should provide for greater means of specifying the data. You can learn more about the schema on the World Wide Web Consortium site, http://www.w3.org/XML/Schema.

3.61 DTD for FileMaker Pro Plug-ins

Troi Automatisering, http://www.troi.com/, is a FileMaker Pro plug-in developer. Peter Baanen has designed an XML Software Description based on the XML Schema Document (XSD) in an effort to standardize the submission of plug-in information to the FileMaker, Inc. web site, http://www.filemaker.com/products/search_plugins.html, and to various other web sites. With this plug-in information standard, one XML document could be submitted to each of these web sites, allowing each one to extract the information on new plug-ins. The same XML document could be used to produce an announcement for emailing or printing. The description becomes a template for submitting similar information. The full Troi XML Software Description can be found at http://www.troi.com/info/xsd/, but for an example, some of the document is provided in Listing 3.11. You can see that this type of schema is very similar to the DTD and XSD.

Listing 3.11: Sample definitions for XSD plug-in
Start example
<!ELEMENT vendor (name,address,city,state,zip,country,phone,fax?,
  email,url?) >
<!ELEMENT address (#PCDATA)>
<!ELEMENT product (name,version,last_release,short_description,
contact name, contact_email,
support_contact_name, support_contact_email,
marketing_contact_name, marketing_contact_email,
engineering_contact_name, engineering_contact_email,
available_for+, fmp_plug_in?) >
End example