Table result to Xml
-
Hi, I am trying to convert a table result to a xml. For example, I have a result (Figure 1) and I want to make an xml out of it (Figure 2). I have tried the FOR XML RAW and FOR XML AUTO but this does not seem to give me the tree structure. Any ideas? Figure 1:
Parent Id Name
0 1 Root
0 2 Root 2
1 3 Child 1
1 4 Child 2
3 5 Child 3
4 6 Child 4
9 7 Child 5Figure 2:
<NodeCollection>
<Node rId=1 Parent=0 Name='Root'>
<Node rId=3 Parent=1 Name='Child 1'>
<Node rId=5 Parent=3 Name='Child 3' />
</Node>
<Node rId=4 Parent=1 Name='Child 2'>
<Node rId=6 Parent=4 Name='Child 4' />
</Node>
</Node>
<Node rId=2 Parent=0 Name='Root 2' />
<Node rId=7 Parent=9 Name='Child 5' />
</NodeCollection> -
Hi, I am trying to convert a table result to a xml. For example, I have a result (Figure 1) and I want to make an xml out of it (Figure 2). I have tried the FOR XML RAW and FOR XML AUTO but this does not seem to give me the tree structure. Any ideas? Figure 1:
Parent Id Name
0 1 Root
0 2 Root 2
1 3 Child 1
1 4 Child 2
3 5 Child 3
4 6 Child 4
9 7 Child 5Figure 2:
<NodeCollection>
<Node rId=1 Parent=0 Name='Root'>
<Node rId=3 Parent=1 Name='Child 1'>
<Node rId=5 Parent=3 Name='Child 3' />
</Node>
<Node rId=4 Parent=1 Name='Child 2'>
<Node rId=6 Parent=4 Name='Child 4' />
</Node>
</Node>
<Node rId=2 Parent=0 Name='Root 2' />
<Node rId=7 Parent=9 Name='Child 5' />
</NodeCollection>Hi Fayu, Have a look at trying for xml explicit, try this article for some help http://www.eggheadcafe.com/articles/20030804.asp[^] Hope you get it working