[Zope3-dev] ZCML alternative

Jim Fulton jim@zope.com
Mon, 03 Jun 2002 09:02:17 -0400


Guido van Rossum wrote:
> 

...

> > ...
> > > Given that our XML schema (or DTD, or whatever) is entirely unique
> >
> > Is that supposed to matter?
> 
> It means that it looks unfamiliar to someone who is used to another
> XML style. 

You are mixing up style and schema. OK, you are really talking about
style, not schema. Or maybe you are talking about the style of the schema.

> I don't know if it matters much, but I understand most XML
> styles have more text in the data and rely much less on attributes.
> 
> > ...
> > > (and not very standard as XML style goes, IMO)
> >
> > Uh, I have no idea what that's supposed to mean.
> 
> I meant that all the info is in the attributes.

OK, so, you maintain that it is unconventional to store data
in attributes, rather than in subelements. Hm, well, I don't
agree. 

Let's look at some examples. How about XML Schema? Surely, that
would follow good style, right? Here's a sample schema:


          <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

           <xsd:annotation>
            <xsd:documentation xml:lang="en">
             Purchase order schema for Example.com.
             Copyright 2000 Example.com. All rights reserved.
            </xsd:documentation>
           </xsd:annotation>

           <xsd:element name="purchaseOrder" type="PurchaseOrderType"/>

           <xsd:element name="comment" type="xsd:string"/>

           <xsd:complexType name="PurchaseOrderType">
            <xsd:sequence>
             <xsd:element name="shipTo" type="USAddress"/>
             <xsd:element name="billTo" type="USAddress"/>
             <xsd:element ref="comment" minOccurs="0"/>
             <xsd:element name="items"  type="Items"/>
            </xsd:sequence>
            <xsd:attribute name="orderDate" type="xsd:date"/>
           </xsd:complexType>

           <xsd:complexType name="USAddress">
            <xsd:sequence>
             <xsd:element name="name"   type="xsd:string"/>
             <xsd:element name="street" type="xsd:string"/>
             <xsd:element name="city"   type="xsd:string"/>
             <xsd:element name="state"  type="xsd:string"/>
             <xsd:element name="zip"    type="xsd:decimal"/>
            </xsd:sequence>
            <xsd:attribute name="country" type="xsd:NMTOKEN"
               fixed="US"/>
           </xsd:complexType>

           <xsd:complexType name="Items">
            <xsd:sequence>
             <xsd:element name="item" minOccurs="0" maxOccurs="unbounded">
              <xsd:complexType>
               <xsd:sequence>
                <xsd:element name="productName" type="xsd:string"/>
                <xsd:element name="quantity">
                 <xsd:simpleType>
                  <xsd:restriction base="xsd:positiveInteger">
                   <xsd:maxExclusive value="100"/>
                  </xsd:restriction>
                 </xsd:simpleType>
                </xsd:element>
                <xsd:element name="USPrice"  type="xsd:decimal"/>
                <xsd:element ref="comment"   minOccurs="0"/>
                <xsd:element name="shipDate" type="xsd:date" minOccurs="0"/>
               </xsd:sequence>
               <xsd:attribute name="partNum" type="SKU" use="required"/>
              </xsd:complexType>
             </xsd:element>
            </xsd:sequence>
           </xsd:complexType>

           <!-- Stock Keeping Unit, a code for identifying products -->
           <xsd:simpleType name="SKU">
            <xsd:restriction base="xsd:string">
             <xsd:pattern value="\d{3}-[A-Z]{2}"/>
            </xsd:restriction>
           </xsd:simpleType>

          </xsd:schema>


Hm, that's interesting, most of the data are in attributes. 
Maybe that's too esoteric. How about something familiar, like 
XHTML? Hm, well, it still has elements like img and input that 
store all their data in attributes.

RDF is an interesting example. Here's an RDF example:

  <rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:s="http://description.org/schema/">
    <rdf:Description about="http://www.w3.org/Home/Lassila">
      <s:Creator>Ora Lassila</s:Creator>
    </rdf:Description>
  </rdf:RDF>

This uses subelements to hold data. I find it hard to find the
creator here, but no worry, RDF supports an alternative "abreviated"
syntax:

  <rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:s="http://description.org/schema/">
    >
    <rdf:Description about="http://www.w3.org/Home/Lassila"
                     s:Creator="Ora Lassila" />
  </rdf:RDF>

Here are two more examples (wo namespave declarations), with data 
in subelements:

  <rdf:RDF>
    <rdf:Description about="http://www.w3.org">
      <s:Publisher>World Wide Web Consortium</s:Publisher>
      <s:Title>W3C Home Page</s:Title>
      <s:Date>1998-10-03T02:27</s:Date>
    </rdf:Description>
  </rdf:RDF>

and with data in attributes:

  <rdf:RDF>
    <rdf:Description about="http://www.w3.org"
         s:Publisher="World Wide Web Consortium"
         s:Title="W3C Home Page"
         s:Date="1998-10-03T02:27"/>
  </rdf:RDF>

Both forms are allowed. I find the attribute form much more readable.

In summary, I am unconvinced that storing data in attributes is
in any way unconventional or non-standard.

Jim

--
Jim Fulton           mailto:jim@zope.com       Python Powered!        
CTO                  (888) 344-4332            http://www.python.org  
Zope Corporation     http://www.zope.com       http://www.zope.org