Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Appending XMLELEMENTs to existing XMLType
I have a self referencing table that I'm trying to build an XML
hierarchy with. The table Categories layout looks like this:
CategoryID Number NOT NULL Primary,
ParentID Number,
Name varchar2(200),
isActive Number(0,1)
xmlagg( xmlelement( "Category", xmlattributes( cata.categoryid as "id", cata.name as "name"), xmlelement( "Category", xmlattributes( catb.categoryid as "id", catb.name as "name")) ) ) ).getclobval()
For example (psuedocode):
function processCategory(catID IN Number) returns XMLNode {
(string or xmltype) catXML = getCategoryXML(); for each childNode in (SELECT * FROM Categories WHERE parentID = catID) catXML = concatenate processCategory(childID) end for loop return catXML
What I want is:
<Categories>
<Category id="2" name="ParentCat1">
<Category id="6" name="ParentCat1Sub1" />
</Category>
<Category id="3" name="ParentCat2" />
...
</Categories>
Any help would be appreciated as I'm on a tight timeline and if I can't get this XML stuff working I will have to switch to a relational model instead and process the code on the frontend (.NET).
Thanks in Advance,
-dpx
Received on Fri Aug 11 2006 - 12:03:02 CDT