Scott Tavares wrote:
>
> Below is my first attempt at an XML schema for the ClassMaps of OPaL. It is
> the equivalent of what I posted as a DTD a few days ago. At this point I'm
> not sure about its validity (especially the namespace thing in the
> preamble). I tried to validate it using IBM's VisualXML but ironically the
> XML Schema is dependent on two DTD files one for Schema Structures and one
> for Schema Datatypes of which the Structures DTD is dependant. I was able to
> validate the Datatypes DTD but I get a "error loading document" message on
> the XML Schema DTD. So if anyone wants to give a try to validate it I would
> be forever grateful ; ).
>
> For those of you who do not know what an XML Schema is, I will do my best to
> summarize:
>
> Basically XML Schema is a replacement for XML DTDs. The funny thing about is
> that an XML Schema is validated by two XML DTDs which means, you can
> correctly infer that an XML Schema file is its self an XML data file... got
> that??? The purpose of the XML Schema it to define and constrain the content
> of an XML data file which as I stated works much like an XML DTD. So...
> what's the point? Well from what I know so far the benefit comes in its
> ability to validate more data types other than character data. XML Schema
> has a predefined set of "primitive datatypes" and a mechanism to allow the
> developer to define custom "complex datatypes". If you want more information
> you can read the two specs:
>
> http://www.w3.org/TR/xmlschema-1/
> http://www.w3.org/TR/xmlschema-2/
Not a bad summary, Scott. You've been reading ;-) In addition to
supporting many more datatypes, you can define a datatype, and then use
that datatype within several different elements, such as a "comment"
element. This is not allowed in DTDs. And as you point out, XML Schema
is simply ... XML ... and easier to use. The rest is stuff not worth
getting into just yet...
>
> Here is the OPaL XMLSchema file for ClassMaps:
>
> ////////////////////////////////////////////////////////////////////////////
> ////////
>
> <?xml version='1.0'?>
> <!-- XML OPaL ClassMap Schema -->
> <!DOCTYPE schema PUBLIC "-//APACHE//DTD OPLXMLSCHEMA 20000111//EN"
> "OPaL.dtd" -->
This is optional... any parser that schema validates will take care of
this for you.
>
> <schema targetNS="http://www.YourDomain.org" version="0.1a"
> xmlns:cm="http://www.YourDomain.org/2000/ClassMapXMLSchema">
You need to add the xml schema namespace. That way elements without
prefixed are handled correctly, and used as part of the XML Schema
namespace. You also should have the namespace you declare (used in your
document, in your case "cm") have the same URI as your target namespace.
<schema targetNS="http://www.YourDomain.org/2000/ClassMapXMLSchema"
version="0.1a"
xmlns="http://www.w3.org/1999/XMLSchema"
xmlns:cm="http://www.YourDomain.org/2000/ClassMapXMLSchema"
>
>
> <element name="ClassMaps">
> <element name="Class" type="cm:Class" minOccurs="1" maxOccurs="*"/>
> </element>
Note that Scott _correctly_ omitted attribute for the namespace
declarations he will need in his XML document (in a DTD you have to add
these as they are seen as any old attribute). In XML Schema, namespaces
are treated more orthogonally, and are left out here for clarity. Nice,
Scott.
>
> <type name="ClassMap">
> <attribute name="Name" type="string"/>
> <attribute name="Proxy" type="boolean" default="false"/>
> <element name="AttributeMap" type="cm:AttributeMap" minOccurs="1"
> maxOccurs="1"/>
> </type>
>
> <type name="AttributeMap">
> <attribute name="Name" type="string"/>
> <attribute name="PKey" type="boolean" default="false"/>
> <attribute name="Proxy" type="boolean" default="false"/>
> <element name="ColumnMap" type="cm:ColumnMap" minOccurs="1"
> maxOccurs="1"/>
> </type>
>
> <type name="ColumnMap">
> <attribute name="Name" type="string"/>
> <element name="TableMap" type="cm:TableMap" minOccurs="1"
> maxOccurs="1"/>
Here you implicitly will get one and only one bahavior, so you don't
need to explicitly specify.
> </type>
>
> <type name="TableMap">
> <attribute name="Name" type="string"/>
> </type>
>
> </schema>
The rest looks OK. Later, when things get more complex, we can look at
stylistic differences, which are minor, but this will do it. Good work
;-)
-Brett
>
> ////////////////////////////////////////////////////////////////////////////
> ////////
>
> -ScottTavares-
>
> ------------------------------------------------------------
> To subscribe: [EMAIL PROTECTED]
> To unsubscribe: [EMAIL PROTECTED]
> Problems?: [EMAIL PROTECTED]
------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Problems?: [EMAIL PROTECTED]