C # recursive generation of XML

Source: Internet
Author: User

Recursive method Everyone should be very familiar with, in short, the method internally called itself, so that repeated repeated repetition of the execution,

But to worry about the cycle of death yo ...

When our system needs to dynamically generate menus, which means that our system's menus are in the database, the database structure is similar to the following:

id,name,parent_id This design approach, we need to dynamically generate menus based on the relationship between ID and parent_id.

As for how to generate the menu, today is not introduced, today is mainly about the use of recursive way to generate XML structure of the document.

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
Namespace H.mysystem.test
12 {
[Testfixture]
Class MyTest
15 {
Public DataTable inittable ()
17 {
DataTable dt = new DataTable ();
19
DT. Columns.Add ("ID", typeof (String));
DT. Columns.Add ("Name", typeof (String));
DT. Columns.Add ("parent_id", typeof (String));
23
The DataRow row1 = dt. NewRow ();
row1["ID"] = "1";
row1["Name"] = "First node";
27
DataRow ROW11 = dt. NewRow ();
row11["ID"] = "11";
row11["Name"] = "4th node";
row11["parent_id"] = "2";
32
Row2 DataRow =<= "" dd= "" class= "" style= "Color:rgb (0, 0, 0);" >

C # recursive generation of XML

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.