Data points: modeling relational data in XML, part 2
-->

Note that we didn't model the customer ID. Columns like IDs that don't represent information that would be meaningful outside the context of the relational database typically shouldn't be modeled in XML documents. The exception to this rule is when a relationship constraint forces a pointer to an element to be added to your XML schema—but again, we'll learn more about modeling relationships in the next article.

An XML document that validates against this document would look like this:


    <customer>


     <customerName>Kevin Williams</customerName>


    </customer>

Using the Ref attribute
The other approach is to use the ref attribute on an element to indicate its name and type based on a global element you've declared elsewhere in your schema. Using this modeling technique, all elements that contain data points are defined as global elements (at the root of the element). The actual declaration of the data point itself (within the context of its container element) then includes a ref attribute that points back to the named element. Here's the same example as before, modeled using ref instead of name and type:


<xsd:schema

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


     <xsd:element name="customerName" type="xsd:string"

    />


     <xsd:element name="customer">


     <xsd:complexType>


     <xsd:sequence>


     <xsd:element ref="customerName" />


     </xsd:sequence>


     </xsd:complexType>


     </xsd:element>


    </xsd:schema>

This schema is functionally equivalent to the previous example: that is, any document that validates against the first example will validate against the second, and vice versa.

Modeling data points as attributes
In XML Schemas, when modeling data points as attributes you have the same two options as if you are modeling the data points with elements: you can either declare the attributes directly using name and type, or you can reference global-level attributes using ref. Let's see some quick examples of each.

Modeling attributes using Name and Type
As before, we include attribute declarations inside of the element complexType with which they are associated. The name of the attribute is specified in the name attribute of the element, and the attribute's data type is specified in the type attribute. Here's an example, similar to the one we used earlier.


Subscribers who liked this article also read:
Modernizing Cobol for the adaptive enterprise
from Hewlett-Packard LP and Intel Corp. For independent software ve...
Multithreaded technology and multi-core processors
by Craig Szydlowski, Infrastructure Processor Division, Intel Corp. ...

If you're interested in this topic, these articles may be helpful:

Source code for 'XML security layers, part 2: core technologies—XML encryption and XML signature'
by Manish Verma, principal architect, Second Foundation. First publ...
XmlPad 2.2. free download
from WMHelp.com XMLPad is based on the unique custom-developed XML ...
Relationships: modeling relational data in XML, part 3
by Kevin Williams, founder and CEO, Blue Oxide Technologies. In thi...
Core Foundation XML parser
from Apple Inc. Core Foundation provides a nonvalidating parser t...
XMLSpy Home Edition 2005
from Altova Altova XMLSpy 2005 Home Edition is a free entry level X...

Related Jobs:

Programmer - MI - Ann Arbor - MS&L Digital
Progressive digital office, located in the heart of modern downtown An...
Member of Technical Staff #05YZhAAM - CA - San Francisco - Salesforce.com, Inc.
Member of Technical Staff Location(s): San Francisco, CA - HQ Appl...
Software Development Principal #002VF - TX - Dallas - Sabre Inc.
Software Development Principal – 002VF Job Description ...
Senior Research Engineer #F2FDC48FE3C2DAE3 - CA - Oakland - Ask Jeeves,Inc.
Title Senior Research Engineer City Oakland State CA Zip Code 94...
Senior Web Applications Engineer #C8469CF29B4A750B - CA - Oakland - Ask Jeeves,Inc.
Title Senior Web Applications Engineer City Oakland State CA Zip...
Data Migration Specialist #TEC00001143 - PA - Horsham - The Thomson Corporation
Data Migration Specialist – TEC00001143 Job Description ...
Engineering Manager / Chief Architect #0D2000E1CDEE90F2 - CA - West Hollywood - Ask Jeeves,Inc.
Title Engineering Manager / Chief Architect City West Hollywood St...
Database & Java Developer #61559 - NY - Depew - HSBC Bank Usa
Database & Java Developer Here are all the details for this position....
Web Facilitator #1544 - OH - Akron - RCG Information Technology
Description-Web Facilitator will assist with general website mainten...
Sr. C# .Net OO Developer #3741826 - TX - Houstan - Ajilon
Description : If you're a professional looking for exciting, new oppo...