C # recursively generate XML,

Source: Internet
Author: User

C # recursively generate XML,

Recursive methods should be familiar to everyone. In short, they are called internally by the method itself, so that repeated and repeated executions are repeated,

But worry about endless loops...

 

When the menu needs to be dynamically generated by our system, that is to say, the menu of our system exists in the database, and the database structure is similar:

 

In the design of ID, Name, Parent_ID, We need to dynamically generate menus based on the relationship between ID and Parent_ID ..

 

As for how to generate menus, we will not introduce them today. Today we will mainly introduce documents that use recursive methods to generate XML structures ..

 

 

1 using System;
2 using System. Collections. Generic;
3 using System. Linq;
4 using System. Text;
5 using System. Data;
6 using System. Collections;
7 using System. Xml;
8
9 using NUnit. Framework;
10
11 namespace H. MySystem. Test
12 {
13 [TestFixture]
14 class MyTest
15 {
16 public DataTable InitTable ()
17 {
18 DataTable dt = new DataTable ();
19
20 dt. Columns. Add ("ID", typeof (string ));
21 dt. Columns. Add ("Name", typeof (string ));
22 dt. Columns. Add ("Parent_ID", typeof (string ));
23
24 DataRow row1 = dt. NewRow ();
25 row1 ["ID"] = "1 ";
26 row1 ["Name"] = "first node ";
27
28 DataRow row11 = dt. NewRow ();
29 row11 ["ID"] = "11 ";
30 row11 ["Name"] = "4th nodes ";
31 row11 ["Parent_ID"] = "2 ";
32
33 DataRow row2 = <= "" dd = "" class = "" style = "color: rgb (0, 0, 0);">

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.