OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help



   RE: [xml-dev] hierarchical XML in a relational DB structure - moving nod

[ Lists Home | Date Index | Thread Index ]
  • To: "Robert Koberg" <rob@koberg.com>, "xml-dev" <xml-dev@lists.xml.org>
  • Subject: RE: [xml-dev] hierarchical XML in a relational DB structure - moving nodes
  • From: "Nathan Young -X \(natyoung - Artizen at Cisco\)" <natyoung@cisco.com>
  • Date: Wed, 24 May 2006 13:11:19 -0700
  • Authentication-results: sj-dkim-2.cisco.com; header.From=natyoung@cisco.com; dkim=pass (sig from cisco.com verified; );
  • Dkim-signature: a=rsa-sha1; q=dns; l=3762; t=1148501484; x=1149365484;c=relaxed/simple; s=sjdkim2001; h=Content-Type:From:Subject:Content-Transfer-Encoding:MIME-Version;d=cisco.com; i=natyoung@cisco.com; z=From:=22Nathan=20Young=20-X=20\(natyoung=20-=20Artizen=20at=20Cisco\)=22=20<natyoung@cisco.com>|Subject:RE=3A=20[xml-dev]=20hierarchical=20XML=20in=20a=20relational=20DB=20structure=20-=20moving=20nodes;X=v=3Dcisco.com=3B=20h=3D/IkeqeuQK3DaBDZgG2ISjQgcX1s=3D; b=ieKpGwu3dB6wFdrzgB+/yLv57OLjraMhEGfxK4LnwEMJOn0yJYJcHC/2g3PZGowRF5AfCl+51EVXeu7R6bb0OJ0e8k1mRkZ3tD7D+lxxCGe/IgcMs4JXHY7HiQsiZonM;
  • Thread-index: AcZ/a6x6L0pw4ezBRzmGbiiNLEDyAwAAIY2Q
  • Thread-topic: [xml-dev] hierarchical XML in a relational DB structure - moving nodes


I can float a couple of ideas but it's hard to know what's going to work
best for you.

My understanding is that squishing indexes down when you remove one or
more ordered children is a pretty common task.  When you are removing
one or more children in a block you can do "update node_table set
parentIndexPosition = parentIndexPosition - (size of block of removed
nodes) where parentIndex = (the index of the parent) and
parentIndexPosition > (the end point of the removed block)".  Opening
space to add in a child is similar but reversed...

Alternately you can model your table:


This is more of a linked list approach.  It lets you go down into the
data pretty easily and it would let you yank siblings without
re-ordering indexes but implementing anything like an ancestor or
preceding sibling axis is going to be difficult.



Nathan Young
CDC Site Design & Development->Interface Development Team
A: ncy1717
E: natyoung@cisco.com  

> -----Original Message-----
> From: Robert Koberg [mailto:rob@koberg.com] 
> Sent: Wednesday, May 24, 2006 12:53 PM
> To: xml-dev
> Subject: [xml-dev] hierarchical XML in a relational DB 
> structure - moving nodes
> Hi,
> I want to use a relational database to store data that is nested and 
> where the order is preserved. I am having a hard time 
> wrapping my head 
> around how to do the following mostly because I don't have much 
> experience with relational databases.
> I am looking at mapping a structure like so:
> <node id="1">
>    <node id="11">
>      <node id="111">
>        <node id="1111"/>
>        <node id="1112"/>
>        <node id="1113"/>
>      </node>
>      <node id="112"/>
>      <node id="113"/>
>      <node id="114"/>
>    </node>
>    <node id="12">
>      <node id="121"/>
>      <node id="122"/>
>      <node id="123"/>
>    </node>
> </node>
> To a relational database that might have a table representing it like:
> Node
> -------
> id
> parentId
> parentIndexPosition
> First question: Is using an index position the best way to 
> maintain the 
> position? (or is preceding and/or following sibling better? 
> or something 
> else?)
> OK, lets say I have imported some data/XML into the above 
> table, giving 
> appropriate parents and index positions.
> Next, say I want to move /node/node[2]/node[@id=121] to the position 
> /node/node[1]/node[1].
> How do you handle updating the index position of other nodes? All 
> children of /node/node[@id=12] will need their 
> parentIndexPosition moved 
> down one. And all children of /node/node[@id=11] will need their 
> parentIndexPosition moved up one. (the ID attributes where 
> abritrarily 
> created and should not indicate position)
> Is there a built in mechanism to do this type of thing in relational 
> databases? If not how would an UPDATE look?
> Are there any java libraries or articles out there that 
> handle this type 
> of thing? (I am having a hard time finding anything with google)
> thanks,
> -Rob
> -----------------------------------------------------------------
> The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
> initiative of OASIS <http://www.oasis-open.org>
> The list archives are at http://lists.xml.org/archives/xml-dev/
> To subscribe or unsubscribe from this list use the subscription
> manager: <http://www.oasis-open.org/mlmanage/index.php>


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS