[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Tree v. Table - A relational XML object model...?


relational xml

On Thu, 27 Feb 2003 Matthew.Bennett@f... wrote:

> I recognized in CS 101 that a binary tree is just a table, skewed 45
> degrees, a non-binary tree a sparse table, skewed 45 degrees. They are
> abstractions of the *same* concept! Hence, it ought to be just as valid to
> speak of XML tables, as XML trees.

I'm no mathematician, but I do store XML in tables. I use a simple schema,
where each row contains a node, and the columns

   location, depth, type, uri, name, content

are defined thus: location contains a number that gives the node's position
in document order, depth contains its distance from the root node, type
corresponds to an integer constant that maps to a node type (element,
attribute, comment, PI), uri is the node's namespace, name a local name,
and content is the value or content. You'd need to add a prefix or
qualified name column if you wanted to retain namespace prefixes.

So the document

   <doc>
     <div>stuff</div>
     <div xmlns="http://my.stuff.com">more stuff</div>
   </doc>

Is stored as

   1, 1, ELEMENT, "", doc, null
   2, 2, ELEMENT, "", div, null
   3, 3, PCDATA, null, null, stuff
   4, 2, ELEMENT, "http://my.stuff.com", div, null
   5, 3, PCDATA, null, null, more stuff 

In practice, I have found that many operations are slow over such a simple
schema, so I add an auxillary column, parent, which contains the rowid of
each node's parent node, and an auxillary table which contains mappings of
element row ids to their children row ids. This makes for quick extraction
of document fragments from the database.

The nice thing about such a simple-minded model, is that it is easy to
build a "parser" that reads an RDBMS cursor and fires off SAX events. Just
add the missing endElement events.

I've given no thought to how one might handle entities, CDATA marked
sections, DOCTYPE declarations, DOCTYPE subset, and probably a dozen other
things.

// Gregory Murphy <Gregory.Murphy@s...>




PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.