Hierarchical xml [message #433516] |
Wed, 02 December 2009 11:17 |
renjivij
Messages: 17 Registered: October 2008
|
Junior Member |
|
|
Im looking for a hierarchical xml to be generated in the format below from a table
containing parent_alias,child_alias,type and level.
Could someone let me know what is the easiest way to generate the xml as below.
I have been trying with dbms_xmlgen.newcontextfromhierarchy but couldnt generate the way i want.
<hierarchy>
<headerdata period="date"
root_alias ="parent_alias"/>
<child level="1" alias="XXXX" type="XXXX" >
<child level="2" alias="XXXX" type="XXXX" />
<child level="2" alias="XXXX" type="XXXX" />
<child level="2" alias="XXXX" type="XXXX" />
<child level="2" alias="XXXX" type="XXXX" >
<child level="3" alias="XXXX" type="XXXX" />
<child level="3" alias="XXXX" type="XXXX" >
<child level="4" alias="XXXX" type="XXXX" />
<child level="4" alias="XXXX" type="XXXX" />
</child>
</child>
</child>
</hierarchy>
|
|
|
|
Re: Hierarchical xml [message #433526 is a reply to message #433522] |
Wed, 02 December 2009 13:21 |
renjivij
Messages: 17 Registered: October 2008
|
Junior Member |
|
|
Data is given below.
Hope this is what you are looking for.
level parent_alias child_alias
1 A61X
2 A61X CM10
2 A61X CM11
2 A61X ZVMD
2 A61X ZVMK
3 ZVMK CM12
3 ZVMK CM1E
4 CM1E CM1F
4 CM1E CM13
<hierarchy>
<headerdata period="31-Nov-2009"
root_alias ="A61X"/>
<child level="1" alias="A61X" type="SVA" >
<child level="2" alias="CM10" type="SVA" />
<child level="2" alias="CM11" type="SVA" />
<child level="2" alias="ZVMD" type="SVA" />
<child level="2" alias="ZVMK" type="SVA" >
<child level="3" alias="CM12" type="SVA" />
<child level="3" alias="CM1E" type="SVA" >
<child level="4" alias="CM1F" type="SVA" />
<child level="4" alias="CM13" type="SVA" />
</child>
</child>
</child>
</hierarchy>
|
|
|
Re: Hierarchical xml [message #433532 is a reply to message #433526] |
Wed, 02 December 2009 16:09 |
renjivij
Messages: 17 Registered: October 2008
|
Junior Member |
|
|
Im able to generate the hierarchy as below.
I would like to add the root element as hiearchy and a header element to this.
Any suggestions how to add this ?
DECLARE
qryctx DBMS_XMLGEN.ctxhandle;
v_date date;
xmldoc CLOB;
BEGIN
qryctx :=
DBMS_XMLGEN.newcontextfromhierarchy
('SELECT level,
XMLElement("child",XMLAttributes(level as "level",child_alias as "alias" )
)
FROM xmlhier
START WITH parent_alias is null
CONNECT BY PRIOR child_alias=parent_alias
');
xmldoc := DBMS_XMLGEN.getXML(qryctx);
DBMS_OUTPUT.put_line(xmldoc);
DBMS_XMLGEN.closecontext(qryctx);
END;
<?xml version="1.0"?>
<child level="1" alias="A61X">
<child level="2" alias="CM10"/>
<child level="2" alias="CM11"/>
<child level="2" alias="ZVMD"/>
<child level="2" alias="ZVMK">
<child level="3" alias="CM12"/>
<child level="3" alias="CM1E">
<child level="4" alias="CM13"/>
<child level="4" alias="CM1F"/>
</child>
</child>
</child>
[Mod-Edit: Frank surrounded code with [code] and [/code] tags to improve readability]
[Updated on: Thu, 03 December 2009 01:17] by Moderator Report message to a moderator
|
|
|