Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I have table with parent and child relation. programmatically (using for each loop) in C# how to create a Parent and child relation (tree view type) xml file using the below table.

Table - FolderTable

ID FolderName ParentID
1 1.0 ParentRoot 0
2 1.1 Hardware 1
3 1.2 Software 1
4 2.0 VS 0
5 2.1 VS2014 4
6 2.1.1 FrameWork 5
7 2.1.2 WCF 5
8 2.2 DATA CTR 4
9 2.2.1 Schema 8
10 2.2.2 ToolBox 8
11 2.3 Training 4
12 2.3.1 ASP.NET 11
13 2.3.2 C# 11

using above table, i need the below xml

XML
<?xml version="1.0" encoding="utf-8" ?>
<product id="1.0 ParentRoot" >
  <product id="1.1 Hardware" />
  <product id="1.2 Software" />
</product>

<product id="2.0 VS" >
  <product id="2.1 VS2014 ">
      <product id="2.1.1 FrameWork" />
      <product id="2.1.2 WCF" />
    </product>

  <product id="2.2   DATA CTR" >
      <product id="2.2.1 Schema" />
      <product id="2.2.2 ToolBox" />
  </product>
  <product id="2.3   Training" >
      <product id="2.3.1 ASP.NET" />
      <product id="2.3.2 C#" />
  </product>
 </product>
Posted
Comments
Sergey Alexandrovich Kryukov 9-May-14 11:19am    
Not clear. XML file is already a parent-child relationship. You can only talk about a different form of presentation of it. What should it be? Why it seems to be a problem? You did not even specify language, platform... nothing.
—SA

1 solution

I see the xml file as follow:
XML
<?xml version="1.0" encoding="utf-8" ?>
<Products>
<Product id=1>
    <ID>1.0</ID>
    <FolderName>ParentRoot</FolderName>
    <ParentID>0</ParentID>
</Product>
<Product id=2>
    <ID>1.1</ID>
    <FolderName>Hardware</FolderName>
    <ParentID>1</ParentID>
</Product>
<!-- and so on...-->

</Products>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900