数据集是这样的:   id      parentId    name
    1        0          系统设置
  2     1      权限管理
  3     2      设置权限
  4     2      修改权限
需要导出成XML文件如下:
  <menu id="1" name="系统设置" >
      <menu id="2"  name="权限管理" >
        <menu id="3" name="设置权限" >   </menu>
        <menu id="4" name="修改权限" >   </menu>
      </menu>
    </menu>请高手指教!谢谢,分数不够还可加!

解决方案 »

  1.   

    http://topic.csdn.net/u/20070907/22/981814fc-9fd5-4c2d-b326-d9070f3efb0d.html
    在csdn上搜索 WriteXml会有很多相关内容
      

  2.   

    利用Xsd工具产生C#强类型,然后利用C#强类型编码产生XML
      

  3.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace WindowsApplication1
    {
        public partial class Form1 : Form
        {
            
            public Form1()
            {
                InitializeComponent();
                System.Data.DataSet ds = new DataSet();
                System.Data.DataTable table = new DataTable("Menu");
                table.Columns.Add("id", typeof(int));
                table.Columns.Add("parentid", typeof(int));
                table.Columns.Add("name", typeof(string));
                ds.Tables.Add(table);
                System.Data.DataRow dRow = table.NewRow();
                dRow["id"] = 1;
                dRow["parentid"] = 0;
                dRow["name"] = "系统设置";
                table.Rows.Add(dRow);
                dRow = table.NewRow();
                dRow["id"] = 2;
                dRow["parentid"] = 1;
                dRow["name"] = "权限管理";
                table.Rows.Add(dRow);
                dRow = table.NewRow();
                dRow["id"] = 3;
                dRow["parentid"] = 2;
                dRow["name"] = "设置权限";
                table.Rows.Add(dRow);
                dRow = table.NewRow();
                dRow["id"] = 4;
                dRow["parentid"] = 2;
                dRow["name"] = "修改权限";
                table.Rows.Add(dRow);            string str="";
                test(table, "0", ref str);
                System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
                doc.LoadXml(str);        }
            private void test(System.Data.DataTable table,string pid,ref string value)
            {
                foreach (System.Data.DataRow dRow in table.Select("parentid=" + pid))
                {
                    value += string.Format("<menu id=\"{0}\" name=\"{1}\">",dRow["id"],dRow["name"]);
                    test(table, dRow["id"].ToString(),ref value);
                    value += "</menu>";
                }
                //value += "</menu>";        }       
        }
    }
      

  4.   

    思路就是自定以xml的格式,然后将数据集填充进去.
    程序楼上的估计可以