如何生成父母&使用数据表的子关系xml文件 [英] How to generate a parent & child relation xml file using data table

查看:91
本文介绍了如何生成父母&使用数据表的子关系xml文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有父母与子女的关系表。在C#中以编程方式(使用每个循环)如何使用下表创建父子关系(树视图类型)xml文件。



表 - FolderTable



ID FolderName ParentID

1 1.0 ParentRoot 0

2 1.1硬件1

3 1.2软件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数据点击率4

9 2.2.1架构8

10 2.2.2工具箱8

11 2.3培训4

12 2.3.1 ASP.NET 11

13 2.3.2 C#11



使用上表,我需要以下xml



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 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>

推荐答案

我看到xml文件如下:

I see the xml file as follow:
<?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>


这篇关于如何生成父母&amp;使用数据表的子关系xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆