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();
}
}
}
目前维护的开源产品:https://gitee.com/475660