I have a stored procedure that accepts an XML document as a parameter, similar in structure, to the following:
<grandparent name="grandpa bob">
<parent name="papa john">
<children>
<child name="mark" />
<child name="cindy" />
</children>
</parent>
<parent name="papa henry">
<children>
<child name="mary" />
</children>
</parent>
</grandparent>
My requirement is to “smooth out” this data so that it can be inserted into a temporary table and further control the procedure, so the above XML will look like this:
Grandparent Name Parent Name Child Name
---------------- --------------- ---------------
grandpa bob papa john mark
grandpa bob papa john cindy
grandpa bob papa henry mary
Currently running using XML Server XML nodes:
SELECT
VIRT.node.value('../../../@name','varchar(15)') 'Grandparent Name',
VIRT.node.value('../../@name','varchar(15)') 'Parent Name',
VIRT.node.value('@name','varchar(15)') 'Child Name'
FROM
@xmlFamilyTree.nodes('/grandparent/parent/children/child') AS VIRT(node)
, ( 1000+ child ), 1 2 . , , (<child), XML . 3 ( node, ), ? , "" , , , - - , ?