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

Re: hierarchical XML in a relational DB structure - moving nod


hierarchical model structure
"Robert Koberg" <rob@k...> wrote:
> Is using an index position the best way to maintain the position? (or is
preceding and/or following sibling better? or something
> else?)

How to best map XML into SQL data is a topic somewhat like sorting -- there's no
single solution.

One consideration is whether you're looking for a generic solution that's
interoperable across several SQL platforms. SQL:2003 provides an XML type (a
column of type XML that preserves structure). It's available with DB2 'Viper',
Microsoft SQL Server 2005 and Oracle 10g, but it's not supported by platforms
such as MySQL.

As for a generic solution, one approach is the Adjacency List described by Joe
Celko (link below). He uses a linking column and UNIQUE constraints to ensure
the hierarchical relationship:
http://www.sqlsummit.com/AdjacencyList.htm

Sometimes a simple, intuitive approach is best. If you want to use an outline
model, you need to use unique, ordered node IDs.

Your mapping structure doe not preserve order because you're using integer IDs.
1111-1113 are greater than 112. An SQL query with an ORDER BY nodeID clause
would return nodes 111, 112, 1111, 1112, 1113. One option is 111.1, 111.2 and
111.3 but integer processing is more expensive than floating point calculations,
so an integer numbering scheme is preferable.

myTable includes:
      nodeID=1110
                  nodeID=1111
                  nodeID=1112
                  nodeID=1113
      nodeID=1120
                  nodeID=1121
                  nodeID=1122


Assuming the example data above,  you can create a slot for a new node between
1111 and 1112 with
UPDATE myTable SET  nodeID = nodeID +1 WHERE nodeID > 1111;

======== Ken North ===========
www.WebServicesSummit.com
www.SQLSummit.com
www.GridSummit.com


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.