Relationships: modeling relational data in XML, part 3
To model a relational structure in a hierarchical form, some workarounds have to be used to handle situations that are too complex to be modeled directly in a parent-child hierarchy. Thus the first step is to decide what the document's root element should be.

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

In this series, we'll take a look at how relationships (in the relational database sense) are modeled in XML. Armed with this information and the information from the articles one and two in this series, you'll be able to dive in and get started modeling your relational data in XML Schemas. In the last article we'll look at a simple case study and walk through the analysis and mapping steps.

Modeling tables in XML
In XML Schemas, tables are modeled as elements. Each element will have either attribute declarations or element declarations with text-only content associated with it; these are the data points associated with the element (for more on modeling data points, see the previous article). So, for each table in our relational database containing data we want to represent in an instance of our XML document, we first create an element to hold that data. There are three approaches to this (much like with data point values). Let's take a look at an example. Say we want to model a document that looks something like this:


<Customer>

<Invoice>

<LineItem />

<LineItem />

</Invoice>

</Customer>

In the first approach, anonymous complex types are used inside element declarations to define where there is further complex content (other element structures representing tables) embedded inside our elements. For our example, we might have a definition that looks like this:


<xsd:schema

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


     <xsd:element name="Customer">


     <xsd:complexType>


     <xsd:sequence>


     <xsd:element name="Invoice" maxOccurs="unbounded">


     <xsd:complexType>


     <xsd:sequence>


     <xsd:element name="LineItem" maxOccurs="unbounded"

    />


     </xsd:sequence>


     </xsd:complexType>


     </xsd:element>


     </xsd:sequence>


     </xsd:complexType>


     </xsd:element>   


    </xsd:schema>


In this example, there is really one element model—that of the root element—that contains the models for all the other elements in the system. While this model gives a good idea of how an actual instance document will look (the hierarchy will be similar), this element model can be a bit difficult to debug.


Subscribers who liked this article also read:
Security considerations for mobile hardware
by Alan Zeichick, principal analyst, Camden Associates. Intel Corp. ...
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:

XML Web services: the long-term security risks
by Andrew Yang, senior director of project management, Westbridge Tech...
Data points: modeling relational data in XML, part 2
by Kevin Williams, founder and CEO, Blue Oxide Technologies. Intel Cor...
Scaling XML parsing on Intel architecture
By Andy Longshaw, Content Master Ltd. Intel Corp. XML provides many b...
Final Cut Pro XML Interchange Format
Apple Inc. The Final Cut Pro XML Interchange Format provides extens...
Oracle Database 10g XML & SQL, Chapter 7: Putting It All Together with XML Pipeline, JSPs, and XSQL
by Mark Scardina, Ben Chang, and Jinyu Wang. McGraw-Hill Osborne Med...

Related Jobs:

Database & Java Developer #61559 - NY - Depew - HSBC Bank Usa
Database & Java Developer Here are all the details for this position....
Microsoft Developer - Senior Consultant #1376 - MN - Richfield - Sogeti USA LLC
Microsoft Developer - Senior Consultant Req. ID: 1376 # Positions:...
Freelance Presentation Layer Architect #1977 - NY - New York - aQuantive, Inc.
Freelance Presentation Layer Architect Job ID: 1977 Business Unit:...
Programmer - MI - Ann Arbor - MS&L Digital
Progressive digital office, located in the heart of modern downtown An...
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 ...
Member of Technical Staff #05YZhAAM - CA - San Francisco - Salesforce.com, Inc.
Member of Technical Staff Location(s): San Francisco, CA - HQ Appl...
Software Developer #BK-DEV - PA - Philadelphia - SunGard
Reference No.: BK-DEV Opening Date: July 17, 2007 Job Title: Softw...
Web Developer/Front End #RX1000022062 - CA - Sunnyvale - Yahoo! Inc.
Web Developer/Front End, Structured Web Search Job No. RX10000...
Engineering Manager / Chief Architect #0D2000E1CDEE90F2 - CA - West Hollywood - Ask Jeeves,Inc.
Title Engineering Manager / Chief Architect City West Hollywood St...