Archive

Archive for December, 2011

How To : Flatten out an XML Hierarchical Structure

December 13, 2011 7 comments

Besides the usual requirement to present XML data in a relational way, sometimes we may also need to flatten the whole XML structure and build parent-child relationships from it.
For instance, converting this :

<root>
 <item>ABC<item>
 <item/>
 <item>
   <subitem>XYZ</subitem>
 </item>
<root>

to

    TAG_ID TAG_NAME        TAG_VALUE          PARENT_TAG_ID
---------- --------------- ---------------- ---------------
         1 root
         2 item            ABC                            1
         3 item                                           1
         4 item                                           1
         5 subitem         XYZ                            4

Read more…