Essentially I am trying to transform the XML I have into a flat data structure using SQL.
My XML is in the following format (I've altered the XML into a subset to make it simpler for my example):
<Actions>
<AddComponent>
<Action>
<DataItem>
<GroupId>1</GroupId>
<Data>
<Id>100</Id>
<Value>Value A</Value>
<Children>
<Data>
<Id>200</Id>
<Value>Value B</Value>
<Children>
<Data>
<Id>300</Id>
<Value>Value C1</Value>
</Data>
<Data>
<Id>301</Id>
<Value>Value C2</Value>
<Children />
</Data>
</Children>
</Data>
</Children>
</Data>
</DataItem>
<DataItem>
<GroupId>2</GroupId>
<Data>
<Id>101</Id>
<Value>Value A</Value>
<Children>
<Data>
<Id>200</Id>
<Value>Value B</Value>
<Children>
<Data>
<Id>302</Id>
<Value>Value C3</Value>
</Data>
</Children>
</Data>
</Children>
</Data>
</DataItem>
</Action>
</AddComponent>
</Actions>
The output I am looking for is the following:
+---------+-----+----------+----------+
| GroupId | Id | Value | ParentId |
+---------+-----+----------+----------+
| 1 | 100 | Value A | NULL |
| 1 | 200 | Value B | 100 |
| 1 | 300 | Value C1 | 200 |
| 1 | 301 | Value C2 | 200 |
| 2 | 101 | Value A | NULL |
| 2 | 200 | Value B | 101 |
| 2 | 302 | Value C3 | 200 |
+---------+-----+----------+----------+
I am not sure on the best method of recursively going through the 'Children' elements. As the number of children could be ad infinitum.