I'm trying to generate a XML file representing a hierarchical relationship between records of a TABLE1 on Oracle 12c Database. The relationship between records of this TABLE1 are stored in another TABLE2 using child_id and parent_id columns.The example below represents a typical XML hierarchy that I need to generate with some basic info from TABLE1.
Example XML: X has 2 children (Y and Z) and Z has 2 children (W and K)
<TABLE1>
<NAME>X</NAME>
<TABLE1>
<NAME>Y</NAME>
</TABLE1>
<TABLE1>
<NAME>Z</NAME>
<TABLE1>
<NAME>W</NAME>
</TABLE1>
<TABLE1>
<NAME>K</NAME>
</TABLE1>
</TABLE1>
</TABLE1>
The XML generated uses TABLE1 name for each rowtag representing a node on the hierarchy. Any other tag at the XML (e.g. NAME) is a column at TABLE1.
I've tried to use CONNECT BY with xmlement / xmlconcat / SYS_CONNECT_BY_PATH without success.
Is there a better angle to attack this problem?