YOUR FEEDBACK
IBM Buys Its Way Out of Antitrust Trouble
Plato wrote: L.L.Bean was never actually a customer of PSI. At most, they we...
SOA World Conference
Virtualization Conference
$50 Savings Expire June 24, 2008... – Register Today!


2007 West
GOLD SPONSORS:
Active Endpoints
Your SOA Needs BPEL for Orchestration
BEA
Virtualized SOA: Adaptive Infrastructure for Demanding Applications
Nexaweb
Overcoming Bandwidth Challenges with Nexaweb
TIBCO
What is Service Virtualization?
SILVER SPONSORS:
WSO2
Using Web Services Technologies and FOSS Solutions
Click For 2007 East
Event Webcasts

2008 East
PLATINUM SPONSORS:
Appcelerator
Think Fast: Accelerate AJAX Development with Appcelerator
GOLD SPONSORS:
DreamFace Interactive
The Ultimate Framework for Creating Personalized Web 2.0 Mashups
ICEsoft
AJAX and Social Computing for the Enterprise
Kaazing
Enterprise Comet: Real–Time, Real–Time, or Real–Time Web 2.0?
Nexaweb
Now Playing: Desktop Apps in the Browser!
Sun
jMaki as an AJAX Mashup Framework
POWER PANELS:
The Business Value
of RIAs
What Lies Beyond AJAX?
KEYNOTES:
Douglas Crockford
Can We Fix the Web?
Anthony Franco
2008: The Year of the RIA
Click For 2007 Event Webcasts
SYS-CON.TV
TODAY'S TOP SOA & WEBSERVICES LINKS


Storing XML in Relational Database Management Systems
Using the Edge table approach

Digg This!

Page 2 of 2   « previous page

Xerces-J is my personal favorite. I used it for parsing the sample XML file shown in Figure 1. You might use a DOM parser instead of a SAX parser. A DOM parser will scan the XML and construct the object model for the whole document in the memory, creating a structure similar to Figure 2. Generally speaking, it's more convenient to work with DOM parsers, because they make the whole object model of the XML available in the memory. For large documents this is a problem because an object models of a big XML document may not fit into the main memory, therefore I prefer working with SAX parsers.

Querying XML Using SQL
Most of the RDBMSs do not support XQuery or XPath. In this section, I will show you how to use SQL for responding to some XPath queries. After shredding the XML document we have the table shown in Figure 5.

In the following examples I will offer several XPath queries and convert them to SQL queries. Note that each parent-child or ancestor-descendant relation corresponds to a self join of the Edge table (that's joining Edge table with itself). The representation in Figure 5 is not the most space efficient one, but it can handle mixed XML content nicely. Although values of the attributes and elements do not have unique names, note that we named them as "text" for better performance.

<book isbn='XY023'>
    <title>XML in Use</title>
    <authors>
      <author>Author1</author>
      <author>Author2</author>
    </authors>
</book>

Example 1: Find the title of the book.

XPath:
/book/title/text()

SQL:
select
    a.value
from
    Edge a, Edge b, Edge c
where
    a.name = 'text' and
    a.parentid = b.id and
    b.name = 'title' and
    b.parentid = c.id and
    c.name = 'book' and
    c.id = 1

There are two self joins for two parent-child relations: the first one is between "title" and its text, and the second one is between the root element "book" and "title."

Example 2: Find all of the authors of the book.

XPath:
/book/authors/author/text()

SQL:
select
    a.value
from
    Edge a, Edge b, Edge c, Edge d
where
    a.name = 'text' and
    a.parentid = b.id and
    b.name = 'author' and
    b.parentid = c.id and
    c.name = 'authors' and
    c.parentid = d.id and
    d.name = 'book' and
    d.id = 1

Example 3: This example is similar to Example 2. It demonstrates the use of lastdesc column. It skips the "authors" element by using // (double slash) instead. Find all of the authors of the book.

XPath:
/book//author/text()

SQL:
select
    a.value
from
    Edge a, Edge b, Edge c
where
    a.name = 'text' and
    a.parentid = b.id and
    b.name = 'author' and
    b.id > c.id and b.id <= c.lastdesc and
    c.name = 'book' and
    c.id = 1

Note that in this example we have b.id greater than c.id and less than or equal to c.lastdesc. That's because all of the descendants of c (root "book") will be between c.id and c.lastdesc.

Acknowledgements
Thanks to Glenn Hoffman for reading and commenting on this article.


Page 2 of 2   « previous page

About Selim Mimaroglu
Selim Mimaroglu is a PhD candidate in computer science at the University of Massachusetts in Boston. He holds an MS in computer science from that school and has a BS in electrical engineering.

SYS-CON India News Desk wrote: When we need to store XML in a Relational Database Management System (RDBMS) we have to think of nonnative ways to store it, since the structure of XML does not fit the flat relations of the RDBMSs. Although some RDBMS vendors support XML storage and XQuery such as Oracle 10g (release 2), this support is not yet common. Some of the well-known RDBMSs are Oracle, DB2, Informix, Sybase IQ, SQL Server, MySQL, and PostgreSQL. If you have one of these products, or a similar product, you should be interested in reading this article.
read & respond »
XML JOURNAL LATEST STORIES . . .
Adobe's Kevin Lynch and Microsoft's Scott Guthrie to Keynote AJAX World RIA Conference & Expo
Two of the biggest launches in Rich Internet Application history took place in 2007/2008 when Adobe launched AIR 1.0 in February '08 and Microsoft launched Silverlight (September '07). At the 6th International AJAXWorld RIA Conference & Expo in October SYS-CON Events is delighted to be
Free Guest Passes for the SOA World Conference & Expo in New York City
SYS-CON's upcoming '3rd International Virtualization Conference & Expo' faculty includes such distinguished speakers as: Al Aghili (Managed Methods), Alan Chhabra (Egenera), Andi Mann (Enterprise Management Associates), Andrew Conte (APC), Andy Astor (EnterpriseDB), Ariel Cohen (Xsigo
Integrated Support for XML Data Management
XML is increasingly being used as the language of data exchange. An XML document based on a DTD or an XML Schema contains data that conforms to a standard structure. A number of technologies, such as ebXML (Electronic Business XML), UDDI (Universal Description, Discovery, and Integrati
SYS-CON's Virtualization Conference & Expo: Themes & Topics
From Application Virtualization to Xen, a round-up of the virtualization themes & topics being discussed in NYC June 23-24, 2008 by the world-class speaker faculty at the 3rd International Virtualization Conference & Expo being held by SYS-CON Events in The Roosevelt Hotel, in midtown
Brazil, India & Venezuela Join South Africa in Objecting to OOXML Standardization
At the eleventh hour Brazil, India and Venezuela joined South Africa in appealing ISO's highly politicized standardization of Microsoft's Office Open XML (OOXML) file format. Meanwhile, the Danish Open Source Business Association has protested the Danish Standard's 'yes' vote for stand
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS
SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

SYS-CON FEATURED WHITEPAPERS


ADS BY GOOGLE
BREAKING XML NEWS
Service-Oriented Architecture and Design Strategies Shows how to Achieve the Benefits of SOA
Research and Markets (htt p://www.researchandmarket s.com/research/ae96f9/app lied_soa_servi)