I am using MS-SQL. I have xml which has structure survey, section, rows, cells. I want to import the values from nodes into three tables which are related dbo.sections, dbo.rows, dbo.cells. For this purpose I have to iterate over this xml. First insert the section and get the scode_indentity() and use it for the insert for child row as FK to inserted section. Then get cell inside the inserted row and to insert it with FK scope_indentity() (id from the inserted parent row node). What is the best practice in this situation to map nodes parent to child, insert and get scope_indentity() and pass it to child values for the insert statement ?
Tables DESCRIPTION:
dbo.sections
dbo.rows -> FK to sections
dbo.cells -> FK to rows
XML DESCRIPTION:
<survey S_VALUE1="45" S_VALUE2="1" S_VALUE3="1">
<section SE_VALUE1="34" SE_VALUE2="1855436" SE_VALUE3="False">
<row R_VALUE1="29" R_VALUE2="7444255">
<cell C_VALUE1="43830582" C_VALUE2="28" C_VALUE3="1" />
<cell C_VALUE1="43830582" C_VALUE2="29" C_VALUE3="1" />
<cell C_VALUE1="43830582" C_VALUE2="30" C_VALUE3="1" />
</row>
<row R_VALUE1="30" R_VALUE2="7444255">
<cell C_VALUE1="43830582" C_VALUE2="31" C_VALUE3="1" />
<cell C_VALUE1="43830582" C_VALUE2="32" C_VALUE3="1" />
<cell C_VALUE1="43830582" C_VALUE2="33" C_VALUE3="1" />
</row>
<row R_VALUE1="31" R_VALUE2="7444255">
<cell C_VALUE1="43830582" C_VALUE2="34" C_VALUE3="1" />
<cell C_VALUE1="43830582" C_VALUE2="35" C_VALUE3="1" />
<cell C_VALUE1="43830582" C_VALUE2="36" C_VALUE3="1" />
</row>
</section>
<section SE_VALUE1="35" SE_VALUE2="1855436" SE_VALUE3="False">
<row R_VALUE1="32" R_VALUE2="7444255"/>
<row R_VALUE1="33" R_VALUE2="7444255"/>
<row R_VALUE1="34" R_VALUE2="7444255"/>
</section>
</survey>