• 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();
            }
        }
    }

    关于作者: 王昕(QQ:475660) 在广州工作生活30余年。十多年开发经验,在Java、即时通讯、NoSQL、BPM、大数据等领域较有经验。
    目前维护的开源产品:https://gitee.com/475660
  • 相关阅读:
    LeetCode-079-单词搜索
    awk学习笔记
    Python实现排列组合算法
    python模拟登录人人
    Python的SQLite数据库使用方法
    C语言排序算法——插入排序算法
    C语言排序算法——简单选择排序算法
    C语言排序算法——冒泡排序算法
    Python学习——python的函数参数传递
    Python学习——实现secure copy功能
  • 原文地址:https://www.cnblogs.com/starcrm/p/1362733.html
Copyright © 2020-2023  润新知