Home » Developer & Programmer » JDeveloper, Java & XML » Hierarchical xml
Hierarchical xml [message #433516] Wed, 02 December 2009 11:17 Go to next message
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 #433522 is a reply to message #433516] Wed, 02 December 2009 12:29 Go to previous messageGo to next message
Michel Cadot
Messages: 63807
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
What should be the result with your example?
Please post a more meaningful example with data other than always XXXX.

Regards
Michel
Re: Hierarchical xml [message #433526 is a reply to message #433522] Wed, 02 December 2009 13:21 Go to previous messageGo to next message
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 Go to previous message
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

Previous Topic: change notification: how to retrieve registrations
Next Topic: How to create an data model of an Oracle to XML schema
Goto Forum:
  


Current Time: Wed Sep 28 14:20:07 CDT 2016

Total time taken to generate the page: 0.15128 seconds