Data points: modeling relational data in XML, part 2
When creating your XML Schema from relational data, each column that contains information you want to model in your schema must have a corresponding data point declaration. There are two ways of doing this.

by Kevin Williams, founder and CEO, Blue Oxide Technologies. Intel Corp.

In the first article in this series, we took a look at the element vs. attribute question for data points and concluded that, for data documents, it makes more sense to model the information as attributes when possible. In this, the second part of our four-part series, we take a look at the issues involved when mapping relational data points (columns) to their XML Schema equivalents.

In this and following articles, we assume that the xsd namespace is mapped to the namespace for XML Schemas v. 1.0: http://www.w3.org/2001/XMLSchema.

Representing data points in XML Schemas
When creating your XML Schema from relational data, each column that contains information you want to model in your schema must have a corresponding data point declaration. As we saw in the first article, there are two ways of doing this: we can model the data point as an element or as an attribute. Let's take a look at how this is done.

Modeling data points as elements
A data point is modeled in an XML Schema using the <xsd:element> element. This element is used to model both elements that contain simple values (data points) and elements that contain further structure—another reason to consider using attributes instead of elements for this purpose. There are a couple of ways you can approach the modeling of the data point: you can either define a global element and then reference it inside your container element using the ref attribute, or you can model the element in place using the name and type attributes. Let's take a look at each mechanism.

Using the name and type attributes
When you model your data points this way, you declare your data point element with the name attribute set to the name of the element containing the datapoint, and the type attribute set to the type of the value contained in the element. This element is then declared in the context of a complexType, either a named complexType or an anonymous complexType declared as part of an element declaration. (Don't worry too much about this distinction right now—we'll learn more about this in the next article). For example, let's say we have a table called Customer we want to model in an XML Schema. The SQL for the table looks something like this:


    CREATE TABLE Customer (


     customerID int,


     customerName varchar(200)


     )

To model the customerName point in our XML Schema using name and type, we would use the following sample element declaration:


<xsd:schema

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


     <xsd:element name="customer">


     <xsd:complexType>


     <xsd:sequence>


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

    />


     </xsd:sequence>


     </xsd:complexType>


     </xsd:element>


    </xsd:schema>

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

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:

Microsoft Developer - Senior Consultant #1376 - MN - Richfield - Sogeti USA LLC
Microsoft Developer - Senior Consultant Req. ID: 1376 # Positions:...
Web Facilitator #1544 - OH - Akron - RCG Information Technology
Description-Web Facilitator will assist with general website mainten...
Software Development Principal #002VF - TX - Dallas - Sabre Inc.
Software Development Principal 002VF Job Description ...
Software Developer #BK-DEV - PA - Philadelphia - SunGard
Reference No.: BK-DEV Opening Date: July 17, 2007 Job Title: Softw...
Database & Java Developer #61559 - NY - Depew - HSBC Bank Usa
Database & Java Developer Here are all the details for this position....
Software Development Engineer - Web Applications #26ADD61C339077DF - CA - Oakland - Ask Jeeves,Inc.
Title Software Development Engineer - Web Applications City Oakland ...
Member of Technical Staff #05YZhAAM - CA - San Francisco - Salesforce.com, Inc.
Member of Technical Staff Location(s): San Francisco, CA - HQ Appl...
Senior Web Applications Engineer #8476E6367126C442 - CA - Oakland - Ask Jeeves,Inc.
Title Senior Web Applications Engineer City Oakland State CA Zip...
Engineering Manager / Chief Architect #0D2000E1CDEE90F2 - CA - West Hollywood - Ask Jeeves,Inc.
Title Engineering Manager / Chief Architect City West Hollywood St...
Senior Web Applications Engineer #C8469CF29B4A750B - CA - Oakland - Ask Jeeves,Inc.
Title Senior Web Applications Engineer City Oakland State CA Zip...