mapping a xml file into closure table model and rendering the XML in order
13 Feb 2012, 16:45
ALEJANDRO NIETO GONZALEZ (2 posts)
after reading the chapter 3 i have been playing around with closure table model. I´m trying to store a xml file with attributes where tag_id will be a key for ordering and where only leaf nodes has value.
I´m thinking of storing attributes in a dependant table named “attributes” rather than being nodes themself, so each node by using a node_id can find easy their own attributes. In this xml file can be sibling nodes of same tag. For example, i could have two nodes with same tag_id ‘1.1’
However, when a select the nodes(xml tags) by using the sql statement described in the book i dont find the way to select them in such an order that a sibling node with its own children node comes first in the order. This only works if i insert into db nodes in sequence but when i move nodes around or i dont follow a sequence but keepign parernt-children relationship the order is not kept.
For example, when i select ordered by tag_id (different of node_id) the order i get is:
SELECT n.node_id, n.tag_id, n.name, l.value
i would like to achieve something like this:
that will represent a xml file like this:
I´ve been thinking of adding in the nodes table another id like sibling_id to identify brothers of same tag_id, but still i did not come out with a UNIQUE SELECT statement to select as i wish.
Any advice or pointing to an url where something similar is trying to be achieved is really aprreciated,
21 Jun 2012, 17:27
Bill Karwin (19 posts)
To apply sibling ordering, you need to create a breadcrumbs string from all the ancestors, and sort by that.
See an example here:
|You must be logged in to comment|