A number of tools are at your disposal to create and validate XML Schema documents. You can find a large list of such tools at http://www.w3.org/XML/Schema#Tools. Although a large list is available, I will review only the two that are commonly used by developers-Microsoft's Visual Studio 2005 and Altova's XMLSpy.
Microsoft made strong efforts to
A XSD document type in Visual Studio enables you to visual create schema documents. You can also create hem directly in the code view as well. Figure 6-4 shows Visual Studio 2005
Figure 6-4
From the available Toolbox, you can drag and drop elements directly onto the design surface. The tool creates all the required code on your
Figure 6-5
As you can see from the figure, you can select the datatypes from a drop-down list directly in the designer. Next, this chapter reviews Altova's XMLSpy.
Altova's XMLSpy is a powerful tool recommended for any serious XML programmer. You will find that the XSD capabilities built into the tool allow you to perform pretty much any XSD task including creating schemas from scratch, from other XML documents, and more. Figure 6-6 shows how XMLSpy allows you to code the schema document directly.
Figure 6-6
You can also design the schema visually and let XMLSpy create the schema code on your behalf. This is presented in Figure 6-7.
Figure 6-7
Just as you could probably see the power and reasoning behind DTDs, I hope that you can appreciate that XML Schema documents are that much more powerful. Their power comes in their incredible flexibility. This chapter took a look at the principles you need to build XML Schema documents and focused on building elements, attributes, and more. You will find that schema documents are a big part of most XML technologies-whether you are working with Web services, RSS feeds, or others.
The
The previous two chapters
This chapter will look at the two forms of the RELAX NG specification: the standard form and the compact form. It will show the way you use these two forms to define XML vocabularies, and compare it with DTDs and XML Schemas. Along the way, you will see how RELAX NG integrates with XML tools and programming languages for validating XML documents and creating objects that map to RELAX NG schemas.
At first glance, there seems to be little need for yet another schema language. DTDs have been around since SGML, so most people are aware of them, and most applications can work with them. XML Schema is also commonly available, integrated with many XML tools, and ratified by the W3C. Still, there are great reasons why you should consider using RELAX NG.
The primary reason to use RELAX NG is simplicity. Anyone who has read the W3C XML Schema specification (all three
Listing 7-1: RELAX NG Schema
|
|
<?xml version="1.0" encoding="UTF-8"?> <grammar xmlns="http://relaxng .org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"> <start> <element name="productCatalog"> <oneOrMore> <element name="product"> <ref name="productDefinition"></ref> </element> </oneOrMore> </element> </start> <define name="productDefinition"> <attribute name="id"><data type="integer"/></attribute> <element name="shortName"><text /></element> <element name="fullName"><text /></element> <element name="description"><text /></element> <element name="components "> <refname ="productDefinition" /> </element> </define> </grammar>
|
|
In the
In addition to simplicity, RELAX NG was defined to be much more modular and
Finally, RELAX NG provides two forms: a normal syntax that uses XML, and a compact syntax. This enables you to define your XML vocabularies using either the well-