PDA

View Full Version : Joining different (nested) levels of an XML


Guest
03-14-2005, 02:34 PM
HI, I have an XMLType column that ha the following XML structure:

<Client>
<Report id = "01">
<Item id = "01" Description = ",a.mdfbnelt;yuk" </Item>
<Item id = "02" Description = "AAAAA;yuk" </Item>
<Item id = "03" Description = "XXXXX" </Item>
</Report>
<Report id = "02">
<Item id = "01" Description = ",ABCDEF" </Item>
<Item id = "02" Description = "JHIKLM" </Item>
<Item id = "03" Description = "OPQRST" </Item>
</Report>
</Client>

I would like to extract and insert data into the following file

Table MyTable(Client, Report_id, Item_id, Description)

So I created the following query
SELECT
extractValue(VALUE(x), '/Client/@id')) Client,
extractValue(VALUE(d), '/Report/@id') Report,
extractValue(VALUE(e), '/Item/@id') Description,
extractValue(VALUE(e), '/Item/@Description) Description
FROM XMLDOC2 x,
TABLE(xmlsequence(extract(VALUE(x), '/Client/Report'))) d,
TABLE(xmlsequence(extract(VALUE(x), '/Client/Report/Item'))) e

But I get the cartesian product of the reports and the items. I would
like to get the items related to a reports AND the report id on the
same line. If it is not possible, I would like to filter out the items
belonging to report; some kind of where clause.

Anybody has an idea?

Thank you,
CCote

Christian
03-16-2005, 05:31 AM
ccote_msl@yahoo.com wrote in message news:<1110839694.835163.171530@l41g2000cwc.googlegroups.com>... HI, I have an XMLType column that ha the following XML structure: <Client> <Report id = "01"> <Item id = "01" Description = ",a.mdfbnelt;yuk" </Item> <Item id = "02" Description = "AAAAA;yuk" </Item> <Item id = "03" Description = "XXXXX" </Item> </Report> <Report id = "02"> <Item id = "01" Description = ",ABCDEF" </Item> <Item id = "02" Description = "JHIKLM" </Item> <Item id = "03" Description = "OPQRST" </Item> </Report> </Client> I would like to extract and insert data into the following file Table MyTable(Client, Report_id, Item_id, Description) So I created the following query SELECT extractValue(VALUE(x), '/Client/@id')) Client, extractValue(VALUE(d), '/Report/@id') Report, extractValue(VALUE(e), '/Item/@id') Description, extractValue(VALUE(e), '/Item/@Description) Description FROM XMLDOC2 x, TABLE(xmlsequence(extract(VALUE(x), '/Client/Report'))) d, TABLE(xmlsequence(extract(VALUE(x), '/Client/Report/Item'))) e But I get the cartesian product of the reports and the items. I would like to get the items related to a reports AND the report id on the same line. If it is not possible, I would like to filter out the items belonging to report; some kind of where clause. Anybody has an idea? Thank you, CCote

Ok, I found out how. I use two FOR loops (implicit cursors). One for
the Reports and one for the Items.

I the filter out the Items with
TABLE(xmlsequence(extract(VALUE(x),
'/Client/Report["'||Report_rec.report_ID||'"]/Item')))

And I get only the Items related to a specific report.


MyLounge.com Site Map
Forum: Cars, Cell Phone, Database, Games, Home Improvement, IT, Music, School, Sports, Web Design, Web Server, Weight Loss

The MyLounge.com forum is intended for informational use only and should not be relied upon and is not a substitute for any advice. The information contained on MyLounge.com are opinions and suggestions of members and is not a representation of the opinions of MyLounge.com. MyLounge.com does not warrant or vouch for the accuracy, completeness or usefulness of any postings or the qualifications of any person responding. Please consult a expert or seek the services of an attorney in your area for more accuracy on your specific situation. Please note that our forums also serve as mirrors to Usenet newsgroups. Many posts you see on our forums are made by newsgroup users who may not be members of MyLounge.com Term of Service