日期:2014-05-20  浏览次数:21088 次

关于LiINQ筛选和排序XML元素的问题-未将对象引用设置到对象的实例
本帖最后由 JCY1009015337 于 2013-02-18 15:23:48 编辑
代码: 
static XElement CreateUserList1()
        {
            XElement man1 = new XElement("Man",
                new XAttribute("ID", "001"),
                new XAttribute("Age", "22"),
                new XElement("Name", "李四"),
                new XElement("XingBie", "男"), 
                new XElement("Phone", "131123456789"), 
                new XElement("Emial", "LiSi@126.com"));
            XElement man2 = new XElement("Man",
               new XAttribute("ID", "002"),
               new XAttribute("Age", "23"),
               new XElement("Name", "张三"),
               new XElement("XingBie", "男"),
               new XElement("Phone", "132333456789"),
               new XElement("Emial", "Zhangsan@126.com"));
            XElement woman1 = new XElement("Woman",
               new XAttribute("ID", "003"),
               new XAttribute("Age", "19"),
               new XElement("Name", "黄花"),
               new XElement("XingBie", "女"),
               new XElement("Phone", "130003456789"),
               new XElement("Emial", "huanghua@126.com"));
            XElement userList = new XElement("UserList",new XAttribute("Count","3"),man1,woman1,man2);
            return userList;
        }
 static void QueryComplexElement()//筛选和排序XML元素
        {
            XElement userList = CreateUserList1();
            var oldUsers = from user in userList.Elements() where int.Parse  (user.Attribute("Age").Value) > 20 orderby user.Attribute("Age").Value descending select user;