Linq to xml:XElement拼装

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace linq
{
    class Program
    {
        static void Main(string[] args)
        {
            XElement x = new XElement("body",
                new XElement("form",
                    new XElement("ID", 99999),
                    new XElement("name", "zhangsan")
                    )
                    );
            XElement y = new XElement("body",
                new XElement("form",
                    new XElement("ID", 88888),
                    new XElement("name", "lisa")
                    )
                    );

            //组装
            XElement z = new XElement("ROOT",
                            new XElement("bodys",
                                x,y
                                )
                                );

            XElement srcTree = new XElement("Root",
                new XElement("Element", 1),
                new XElement("Element", 2),
                new XElement("Element", 3),
                new XElement("Element", 4),
                new XElement("Element", 5)
            );
            XElement xmlTree = new XElement("Root",
                new XElement("Child", 1),
                new XElement("Child", 2),
                from el in srcTree.Elements()
                where (int)el > 2
                select el
            );


            Console.WriteLine(z);
            Console.ReadLine();
        }
    }
}

posted @ 2008-12-26 10:00  昕友软件开发  阅读(403)  评论(0编辑  收藏  举报
欢迎访问我的开源项目:xyIM企业即时通讯