|
Article Excerpt THE XML SCHEMA DEFINITION LANGUAGE SOLVES A NUMBER OF PROBLEMS POSED WITH DOCUMENT TYPE DEFINITIONS. BECAUSE DTDS PROMPTED MUCH CONFUSION AND COMPLAINING AMONG XML DEVELOPERS, THE W3C SET ABOUT CREATING A NEW STANDARD FOR DEFINING a DOCUMENT'S STRUCTURE.
WHAT The W3C CREATED IS SOMETHING EVEN MORE COM PLEX AND FLEXIBLE THAN DTDs: THE XML SCHEMA DEFINITION LANGUAGE. IN This ARTICLE WE'LL LOOK AT MANY ASPECTS OF SCHEMAS AND HOW YOU CAN BUILD AND USE THEM.
A Little Background
Schemas, while more complex than DTDs, give an individual much more power and control over how XML documents are validated. For instance, with the new W3C standard a document definition can specify the data type of an element's contents, the range of values for elements, the minimum as well as maximum number of times an element may occur, annotations to schemas, and much more.
In May of 2001 the W3C finalized its recommendation for the XML Schema Definition Language. This standard allows an author to define simple and complex elements as well as the rules governing how those elements and their attributes may show up within an instance document. The author has a large amount of control over how the structure of a conforming XML document must be created. The author can apply various restrictions to the elements and attributes within the document, from specifying the length to specifying an enumerated set of acceptable values for the element or attribute. With the XML Schema Definition Language, an XML schema author possesses an incredible amount of control over the conformance of an associated XML document to the specified schema.
Sample XML Document
The remainder of this article is devoted to creating and understanding the XML schema for the XML document shown in Listing 1, which details a purchase order for various items that can commonly be found in a grocery store. This document allows one individual to receive the shipment of the goods and an entirely different individual to pay for the purchase. This document also contains specific information about the products ordered, such as how much each product cost, how many were ordered, and so on.
LISTING 1 PurchaseOrder.xml Dillon Larsen 123 Jones Rd. Houston TX 77381 USPS 2001-08-12 Madi Larsen 123 Jones Rd. Houston TX 77381 Credit Card 2001-08-09
As you can see, the listing represents a fairly small and simple order that could be placed online. It contains the necessary information regarding how payment is to be made, how the order is to be shipped, and what day delivery should be. The listing should by no means be construed as an all-inclusive document for an online grocery store order; it has been constructed only for use as an example.
For the listing, an author might construct a DTD to describe the XML document. While such a DTD might require only 30 lines or so, it would provide a relatively inflexible definition of the XML document.
A Sample Schema
Creating an XML schema to describe this document is somewhat more complex than building a DTD. However, in exchange for the extra complexity, the schema gives the author virtually limitless control over how an XML document can be validated against it.
Authoring an XML schema consists of declaring elements and attributes as well as the "properties" of those elements and attributes. We will begin our look at authoring XML schemas by working our way from the least complex to the most complex example. Because attributes may not contain other attributes or elements, we will start there.
Declaring attributes
Attributes in an XML document are contained by elements. To indicate that a complex element has an attribute, use the element...
|
|

More articles from XML Journal
Model-driven programming using XSLT: an approach to rapid development ..., August 01, 2002 Show report. (web services Edge conference & expo).(SYS-CON's Web Serv..., August 01, 2002 New release of GoXML Transform 3.0. (XML News).(Product Announcement)(..., August 01, 2002 Updated Blaze Advisor from HNC. (XML News).(Blaze Advisor from HNC 4.2..., August 01, 2002 Tamino XML Server integrated with Stellent CM system.(Brief Article), August 01, 2002
Looking for additional articles?
Search our database of over 3 million articles.
Looking for more in-depth information on this industry?
Search our complete database of Industry & Market reports by text, subject, publication
name or publication date.
About Goliath
Whether you're looking for sales prospects, competitive information, company
analysis or best practices in managing your organization,
Goliath can help you meet your business needs.
Our extensive business information databases empower business
professionals with both the breadth and depth of credible,
authoritative information they need to support their business
goals. Whether it be strategic planning, sales prospecting,
company research or defining management best practices -
Goliath is your leading source for accurate information.
|
|