Can XQuery handle hierarchical data?

  • Thread starter mikharakiri_nospaum
  • Start date
M

mikharakiri_nospaum

Is hierarchical aggregated total expressible in XQuery? Given

<emp name = ALLEN sal = 2000>
<emp name = SMITH sal = 1500>
</emp>
<emp name = MILLER sal = 1800>
<emp name = ADAMS sal = 1000>
</emp>
</emp>
</emp>

the result is supposed to be

<emp name = ALLEN budget = 4300>
<emp name = SMITH budget = 1500>
</emp>
<emp name = MILLER budget = 2800>
<emp name = ADAMS budget = 1000>
</emp>
</emp>
</emp>
 
N

Neo

Script below models the hierarchy with an experimental db (not XQuery)
and walks the tree recursively.

// Create persons
(CREATE *person.item ~in = dir)
(CREATE *allen.cls = person)
(CREATE *smith.cls = person)
(CREATE *miller.cls = person)
(CREATE *adam.cls = person)

// Create salaries
(CREATE *salary.item ~in = dir)
(CREATE allen.salary=+2000)
(CREATE smith.salary=+1500)
(CREATE miller.salary=+1800)
(CREATE adam.salary=+1000)

// Create verbs for heirarchy
(CREATE *boss.cls = verb)
(CREATE boss.vbType = kr)
(CREATE *employee.cls = verb)
(CREATE employee.vbType = cr)
(CREATE boss.opposite = employee)

// Create hierarchy
(CREATE allen.employee = smith)
(CREATE allen.employee = miller)
(CREATE miller.employee = adam)

// Selects allen's empolyees recursively
// Selects smith, miller, adam
(SELECTR allen.employee)
 
M

mikharakiri_nospaum

Neo said:
Script below models the hierarchy with an experimental db (not XQuery)
and walks the tree recursively.
....

Impressive! When googled "Bill of materials XQuery", however, the first
entry is 3 pages of spaghetty code in XSLT:
http://forums.tamino.com/3/OpenTopic?a=tpc&f=7922934291&m=656106161"
Try to beat that!

Now, every other google reference on that page claims that Bill of
materials extremely easy to do in XML. Which bill of materials? Finding
all the descendants? Perhaps. The question is if query ability scales
up so something little more complicated than that. Finding aggrergated
cost of all the subparts, for example.
 
J

Jan Hidders

Is hierarchical aggregated total expressible in XQuery? Given

<emp name = ALLEN sal = 2000>
<emp name = SMITH sal = 1500>
</emp>
<emp name = MILLER sal = 1800>
<emp name = ADAMS sal = 1000>
</emp>
</emp>
</emp>

the result is supposed to be

<emp name = ALLEN budget = 4300>
<emp name = SMITH budget = 1500>
</emp>
<emp name = MILLER budget = 2800>
<emp name = ADAMS budget = 1000>
</emp>
</emp>
</emp>

Hi Mikito,

Did you already find the answer?

-- Jan Hidders
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,838
Latest member
KandiceChi

Latest Threads

Top