当前位置: 首页>>代码示例>>C#>>正文


C# XElement.RemoveAll方法代码示例

本文整理汇总了C#中System.Xml.Linq.XElement.RemoveAll方法的典型用法代码示例。如果您正苦于以下问题:C# XElement.RemoveAll方法的具体用法?C# XElement.RemoveAll怎么用?C# XElement.RemoveAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Xml.Linq.XElement的用法示例。


在下文中一共展示了XElement.RemoveAll方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateXmlContent

 protected override void GenerateXmlContent(XElement RootNode)
 {
     //清空节点原有数据
     RootNode.RemoveAll();
     //所有飞机运行记录(引进类型的飞机)
     var AllOperationHistory = this.GetAllAircraftOperationHistory().Where(p =>
             p.ImportCategory.ActionType == "引进").ToList();
     //引进方式列表
     IEnumerable<string> AircraftImportList = this.GetAllImportTypeList();
     DateTime startTime = GetOperationStartDate();
     DateTime endTime = GetOperationEndDate();
     for (DateTime time = startTime; time <= endTime; time = GetMonthEndofDateTime(time.AddMonths(1)))
     {
         //计算time对应时间所有引进飞机
         var MonthOperationHistory = AllOperationHistory.Where(p => p.StartDate <= time && !(p.EndDate != null && p.EndDate < time));
         //时间节点
         XElement DateTimeNode = new XElement("DateTime", new XAttribute("EndOfMonth", FormatDate(time)));
         RootNode.Add(DateTimeNode);
         //引进飞机总数
         int Amount = MonthOperationHistory.Count();
         //引进方式
         XElement RegionalNode = new XElement("Type", new XAttribute("TypeName", "引进方式"), new XAttribute("Amount", Amount));
         DateTimeNode.Add(RegionalNode);
         // 各种引进方式
         foreach (var name in AircraftImportList)
         {
             int AirNum = MonthOperationHistory.Where(p => this.SameImportType(p.ImportCategory.ActionName, name)).Count();
             XElement CategoryNode = new XElement("Item", new XAttribute("Name", name), new XAttribute("Percent", GetPercent(AirNum, Amount)), AirNum);
             RegionalNode.Add(CategoryNode);
         }
     }
 }
开发者ID:unicloud,项目名称:AFRP,代码行数:32,代码来源:ImportTypeXml.cs

示例2: GenerateXmlContent

 protected override void GenerateXmlContent(XElement RootNode)
 {
     //清空节点原有数据
     RootNode.RemoveAll();
     //所有飞机
     var AllAircraft = this.GetAllAircraft().Where(o => o.FactoryDate != null).ToList();
     //所有机型
     var AircraftTypeList = this.GetAllAircraftTypeList();
     //按月生成每个月的数据
     DateTime startTime = GetMonthEndofDateTime(Convert.ToDateTime(AllAircraft.Min(p => p.FactoryDate)));
     DateTime endTime = GetMonthEndofDateTime(DateTime.Now);
     if (startTime.Year < 1900) startTime = endTime;
     for (DateTime time = startTime; time <= endTime; time = GetMonthEndofDateTime(time.AddMonths(1)))
     {
         //生成时间节点
         XElement DateTimeNode = new XElement("DateTime", new XAttribute("EndOfMonth", FormatDate(time)));
         RootNode.Add(DateTimeNode);
         //每个月份可计算机龄的飞机集合
         var MonthAircraft = AllAircraft.Where(o => o.AircraftBusinesses.Any(p => p.StartDate <= time && !(p.EndDate != null && p.EndDate < time)) && o.FactoryDate <= time && !(o.ExportDate != null && o.ExportDate < time));
         //所有飞机的平均机年龄分布
         GetAgeNodeByDateTime(ref DateTimeNode, MonthAircraft, time, "所有机型");
         foreach (string AircraftType in AircraftTypeList)
         {
             GetAgeNodeByDateTime(ref DateTimeNode, MonthAircraft, time, AircraftType);
         }
     }
 }
开发者ID:unicloud,项目名称:AFRP,代码行数:27,代码来源:FleetAgeXml.cs

示例3: GenerateXmlContent

        protected override void GenerateXmlContent(XElement RootNode)
        {
            //清空节点原有数据
            RootNode.RemoveAll();
            //当前版本的计划
            var AllPlan = GetAllPlan().ToList();
            //航空公司列表
            IEnumerable<string> AirLinesList = AllPlan.Select(p => p.Airlines.CnShortName).Distinct();
            //开始年
            int BeginYear = !AllPlan.Any() ? DateTime.Now.Year : AllPlan.Min(q => q.Annual.Year);
            //结束年
            int EndYear = !AllPlan.Any() ? DateTime.Now.Year : AllPlan.Max(q => q.Annual.Year);

            //按年生成每年的数据
            for (int year = BeginYear; year <= EndYear; year++)
            {
                //时间节点
                XElement DateTimeNode = new XElement("DateTime", new XAttribute("EndOfMonth", year.ToString()));
                RootNode.Add(DateTimeNode);

                //年度计划
                var YearPlan = AllPlan.Where(p => p.Annual.Year == year);
                //航空公司节点
                XElement TypeNode = new XElement("Type", new XAttribute("TypeName", "航空公司"));
                DateTimeNode.Add(TypeNode);
                //每个航空公司节点
                foreach (var name in AirLinesList) // 航空公司
                {
                    var AirlinesPlan = YearPlan.Where(p => p.Airlines.CnShortName == name);
                    decimal AirlinesPercent = GetPlanPerformance(AirlinesPlan);
                    XElement AirlinesNode = new XElement("Item", new XAttribute("Name", name), FormatDecimal(AirlinesPercent));
                    TypeNode.Add(AirlinesNode);
                }
            }
        }
开发者ID:unicloud,项目名称:FRP,代码行数:35,代码来源:PlanPerformXml.cs

示例4: Test

    public void Test()
    {
      DatabaseOptions option = new DatabaseOptions()
      {
        Location = "c:\\d",
        AccessNumberPattern = "ddd",
        ContaminationNamePattern = "ccc",
        DecoyPattern = "eee",
        RemovePeptideFromDecoyDB = true
      };

      XElement root = new XElement("Root");
      option.Save(root);

      DatabaseOptions target = new DatabaseOptions();
      target.Load(root);

      root.RemoveAll();
      target.Save(root);

      Assert.AreEqual(option.Location, target.Location);
      Assert.AreEqual(option.AccessNumberPattern, target.AccessNumberPattern);
      Assert.AreEqual(option.ContaminationNamePattern, target.ContaminationNamePattern);
      Assert.AreEqual(option.DecoyPattern, target.DecoyPattern);
      Assert.AreEqual(option.RemovePeptideFromDecoyDB, target.RemovePeptideFromDecoyDB);
    }
开发者ID:shengqh,项目名称:RCPA.Test,代码行数:26,代码来源:TestDatabaseOptions.cs

示例5: GenerateXmlContent

        protected override void GenerateXmlContent(XElement RootNode)
        {
            //清空节点原有数据
            RootNode.RemoveAll();
            //获取所有飞机
            var AllAircraft = this.GetAllAircraft();
            //供应商列表
            IEnumerable<string> SupplierList = _XmlService.AllOwnershipHistory.Select(q => q.Supplier.CnShortName).Distinct();
            //按月生成每个月的数据
            DateTime startTime = GetOperationStartDate();
            DateTime endTime = GetOperationEndDate();
            for (DateTime time = startTime; time <= endTime; time = GetMonthEndofDateTime(time.AddMonths(1)))
            {
                //时间节点
                XElement DateTimeNode = new XElement("DateTime", new XAttribute("EndOfMonth", FormatDate(time)));
                RootNode.Add(DateTimeNode);
                //当前时间点的飞机总数
                int Amount = AllAircraft.Count(p => p.OperationHistories.Any(pp => pp.StartDate <= time && !(pp.EndDate != null && pp.EndDate < time)) &&
                                                    p.OwnershipHistories.Any(pp => pp.StartDate <= time && !(pp.EndDate != null && pp.EndDate < time)));
                //供应商节点
                XElement SupplierNode = new XElement("Type", new XAttribute("TypeName", "供应商"), new XAttribute("Amount", Amount));
                DateTimeNode.Add(SupplierNode);

                //各个供应商数据节点
                foreach (var name in SupplierList)
                {
                    int AirNum = AllAircraft.Count(p => p.OperationHistories.Any(pp => pp.StartDate <= time && !(pp.EndDate != null && pp.EndDate < time)) &&
                                                        p.OwnershipHistories.Any(pp => pp.Supplier.CnShortName == name &&
                                                                                       pp.StartDate <= time && !(pp.EndDate != null && pp.EndDate < time)));
                    XElement EachSupplierNode = new XElement("Item", new XAttribute("Name", name), new XAttribute("Percent", GetPercent(AirNum, Amount)), AirNum);
                    SupplierNode.Add(EachSupplierNode);
                }
            }
        }
开发者ID:unicloud,项目名称:FRP,代码行数:34,代码来源:SupplierXml.cs

示例6: GenerateXmlContent

 protected override void GenerateXmlContent(XElement RootNode)
 {
     //清空节点原有数据
     RootNode.RemoveAll();
     //获取所有飞机
     var AllAircraft = this.GetAllAircraft().ToList();
     //所有制造商列表
     IEnumerable<string> ManafacturerList = AllAircraft.Select(p => p.AircraftType.Manufacturer.CnName).Distinct();
     //按月生成每个月的数据
     DateTime startTime = GetOperationStartDate();
     DateTime endTime = GetOperationEndDate();
     for (DateTime time = startTime; time <= endTime; time = GetMonthEndofDateTime(time.AddMonths(1)))
     {
         //当前时间点的所有飞机
         var MonthAircraft = AllAircraft.Where(p => p.OperationHistories.Any(pp =>
              pp.StartDate <= time && !(pp.EndDate != null && pp.EndDate < time)));
         //时间节点
         XElement DateTimeNode = new XElement("DateTime", new XAttribute("EndOfMonth", FormatDate(time)));
         RootNode.Add(DateTimeNode);
         //飞机总数
         int Amount = MonthAircraft.Count();
         //制造商节点
         XElement ManafacturerNode = new XElement("Type", new XAttribute("TypeName", "制造商"), new XAttribute("Amount", Amount));
         DateTimeNode.Add(ManafacturerNode);
         //各个制造商数据节点
         foreach (var name in ManafacturerList)
         {
             int AirNum = MonthAircraft.Where(p => p.AircraftType.Manufacturer.CnName == name).Count();
             XElement EachManaFacturerNode = new XElement("Item", new XAttribute("Name", name), new XAttribute("Percent", GetPercent(AirNum, Amount)), AirNum);
             ManafacturerNode.Add(EachManaFacturerNode);
         }
     }
 }
开发者ID:unicloud,项目名称:FRP,代码行数:33,代码来源:ManufacturerXml.cs

示例7: XLinq5

 public void XLinq5() {
     XmlReader reader = XmlReader.Create(dataPath + "config.xml");
     //the file has comments and whitespace at the start
     reader.Read();
     reader.Read();
     XElement config = new XElement("appSettings",
                                    "This content will be replaced");
     config.RemoveAll();
     while (!reader.EOF)
         config.Add(XNode.ReadFrom(reader));
     Console.WriteLine(config);
 }
开发者ID:FabioOstlind,项目名称:TestRepo,代码行数:12,代码来源:LinqToXmlSamples.cs

示例8: ContainerAdd

                /// <summary>
                /// Tests the Add methods on Container.
                /// </summary>
                /// <param name="context"></param>
                /// <returns></returns>
                //[Variation(Desc = "ContainerAdd")]
                public void ContainerAdd()
                {
                    XElement element = new XElement("foo");

                    // Adding null does nothing.
                    element.Add(null);
                    Validate.Count(element.Nodes(), 0);

                    // Add node, attrbute, string, some other value, and an IEnumerable.
                    XComment comment = new XComment("this is a comment");
                    XComment comment2 = new XComment("this is a comment 2");
                    XComment comment3 = new XComment("this is a comment 3");
                    XAttribute attribute = new XAttribute("att", "att-value");
                    string str = "this is a string";
                    int other = 7;

                    element.Add(comment);
                    element.Add(attribute);
                    element.Add(str);
                    element.Add(other);
                    element.Add(new XComment[] { comment2, comment3 });

                    Validate.EnumeratorDeepEquals(
                        element.Nodes(),
                        new XNode[] { comment, new XText(str + other), comment2, comment3 });

                    Validate.EnumeratorAttributes(element.Attributes(), new XAttribute[] { attribute });

                    element.RemoveAll();
                    Validate.Count(element.Nodes(), 0);

                    // Now test params overload.
                    element.Add(comment, attribute, str, other);

                    Validate.EnumeratorDeepEquals(
                        element.Nodes(),
                        new XNode[] { comment, new XText(str + other) });

                    Validate.EnumeratorAttributes(element.Attributes(), new XAttribute[] { attribute });

                    // Not allowed to add a document as a child.
                    XDocument document = new XDocument();
                    try
                    {
                        element.Add(document);
                        Validate.ExpectedThrow(typeof(ArgumentException));
                    }
                    catch (Exception ex)
                    {
                        Validate.Catch(ex, typeof(ArgumentException));
                    }
                }
开发者ID:johnhhm,项目名称:corefx,代码行数:58,代码来源:SDMContainer.cs

示例9: GenerateXmlContent

        protected override void GenerateXmlContent(XElement RootNode)
        {
            //清空节点原有数据
            RootNode.RemoveAll();
            //获取所有的飞机
            var OprerationAf = this.GetAllAircraft().Where(p => p.IsOperation == true);
            //计划中的客机
            var AircraftPnr = OprerationAf == null ?
                    null :
                    OprerationAf.Where(p => p.AircraftType.AircraftCategory.Category == "客机");

            //计划中的货机机
            var AircraftCargo = OprerationAf == null ?
                    null :
                    OprerationAf.Where(p => p.AircraftType.AircraftCategory.Category == "货机");

            if (AircraftPnr != null || AircraftPnr.Any())
            {
                //客机总计划数
                decimal totalAfCount = AircraftPnr.Count();
                //客机的子节点
                XElement PnrNode = new XElement("Pnr", new XAttribute("Amount", totalAfCount));
                //根据航空公司分组,统计客机的各个航空公司所在的比例
                foreach (var Item in AircraftPnr.GroupBy(t => t.Airlines.ShortName))
                {
                    //获取节点
                    XElement ItemNode = new XElement("Type",
                         new XAttribute(Item.Key.ToString(), Item.Count()),
                         new XAttribute("Percent", GetPercent(Item.Count(), totalAfCount)));
                    PnrNode.Add(ItemNode);
                }
                RootNode.Add(PnrNode);
            }

            if (AircraftCargo != null || AircraftCargo.Any())
            {
                //货机总计划数
                decimal totalAfCount = AircraftCargo.Count();
                //货机的子节点
                XElement CargoNode = new XElement("Cargo", new XAttribute("Amount", totalAfCount));
                //根据航空公司分组,统计货机的各个航空公司所在的比例
                foreach (var Item in AircraftCargo.GroupBy(t => t.Airlines.ShortName))
                {
                    //获取节点
                    XElement ItemNode = new XElement("Type",
                         new XAttribute(Item.Key.ToString(), Item.Count()),
                         new XAttribute("Percent", GetPercent(Item.Count(), totalAfCount)));
                    CargoNode.Add(ItemNode);
                }
                RootNode.Add(CargoNode);
            }
        }
开发者ID:unicloud,项目名称:AFRP,代码行数:52,代码来源:OperationAircraftXml.cs

示例10: SaveFeeds

        public static void SaveFeeds(List<RssFeed> feedList)
        {
            XDocument xml = XDocument.Load(RssDataPath);
            XElement element = new XElement("Feeds");
            element.RemoveAll();

            XElement newXml = new XElement("Feeds",
                                        from f in feedList
                                        select new XElement("Feed",
                                                    new XElement("Url", f.Url),
                                                    new XElement("LastUpdated", f.LastUpdated))
                                       );
            newXml.Save(RssDataPath);
        }
开发者ID:ICanHaz,项目名称:RssViewer,代码行数:14,代码来源:FeedHelper.cs

示例11: GenerateXmlContent

        protected override void GenerateXmlContent(XElement RootNode)
        {
            RootNode.RemoveAll();
            //所有飞机
            List<Aircraft> AllAircraft = this.GetAllAircraft().ToList();
            //所有座级
            List<string> AircraftRegionalList = this.GetAllAircraftAircraftBusiness().Select(p => p.AircraftType.AircraftCategory.Regional).Distinct().ToList();
            //所有机型
            List<string> AircraftTypeList = this.GetAllAircraftAircraftBusiness().Select(p => p.AircraftType.Name).Distinct().ToList();

            DateTime startTime = GetOperationStartDate();
            DateTime endTime = GetOperationEndDate();
            for (DateTime time = startTime; time <= endTime; time = GetMonthEndofDateTime(time.AddMonths(1)))
            {

                //得到time对应时间的所有飞机,且在该时间点处于运行状态
                var MonthAircraft = AllAircraft.Where(p => p.OperationHistories.Any(pp => pp.StartDate <= time && !(pp.EndDate != null && pp.EndDate < time))
                    && p.AircraftBusinesses.Any(pp => pp.StartDate <= time && !(pp.EndDate != null && pp.EndDate < time)));
                //日期节点
                XElement DateTimeNode = new XElement("DateTime", new XAttribute("EndOfMonth", FormatDate(time)));
                RootNode.Add(DateTimeNode);
                //总飞机数
                int Amount = MonthAircraft.Count();

                //座级
                XElement RegionalNode = new XElement("Type", new XAttribute("TypeName", "座级"), new XAttribute("Amount", Amount));
                DateTimeNode.Add(RegionalNode);
                // 所有座级
                foreach (string name in AircraftRegionalList)
                {
                    int AirNum = MonthAircraft.Count(p =>
                            p.AircraftBusinesses.FirstOrDefault(q => q.StartDate <= time && !(q.EndDate != null && q.EndDate < time)).AircraftType.AircraftCategory.Regional == name);
                    XElement CategoryNode = new XElement("Item", new XAttribute("Name", name), new XAttribute("Percent", GetPercent(AirNum, Amount)), AirNum);
                    RegionalNode.Add(CategoryNode);
                }

                //机型
                XElement TypeNode = new XElement("Type", new XAttribute("TypeName", "机型"), new XAttribute("Amount", Amount));
                DateTimeNode.Add(TypeNode);
                // 所有机型
                foreach (string name in AircraftTypeList)
                {
                    int AirNum = MonthAircraft.Count(p => p.AircraftBusinesses.FirstOrDefault(q => q.StartDate <= time && !(q.EndDate != null && q.EndDate < time)).AircraftType.Name == name);
                    XElement CategoryNode = new XElement("Item", new XAttribute("Name", name), new XAttribute("Percent", GetPercent(AirNum, Amount)), AirNum);
                    TypeNode.Add(CategoryNode);
                }
            }
        }
开发者ID:unicloud,项目名称:FRP,代码行数:48,代码来源:AirCraftTypeXml.cs

示例12: AddingMultipleNodesIntoElement

        public void AddingMultipleNodesIntoElement(TestedFunction testedFunction, CalculateExpectedValues calculateExpectedValues)
        {
            runWithEvents = (bool)Params[0];
            var isConnected = (bool)Variation.Params[0];
            var lengthOfVariations = (int)Variation.Params[1];

            object[] toAdd = { new XElement("ToAddEmpty"), new XElement("ToAddWithAttr", new XAttribute("id", "a1")), new XElement("ToAddWithContent", new XAttribute("id", "a1"), new XElement("inner", "innerContent"), "content"), new XProcessingInstruction("PiWithData", "data"), "", new XProcessingInstruction("PiNOData", ""), new XComment("comment"), new XCData("xtextCdata"), new XText("xtext"), "plaintext1", "plaintext2", null };

            if (isConnected)
            {
                var dummy = new XElement("dummy", toAdd);
            }

            var referenceElement = new XElement("testElement", "text0", new XElement("tin"), new XElement("tin2", new XAttribute("id", "a2")), //
                "text1", new XAttribute("hu", "ha"), new XProcessingInstruction("PI", "data"), new XText("heleho"), new XComment("M&M"), "textEnd");

            for (int startPos = 0; startPos < referenceElement.Nodes().Count(); startPos++)
            {
                // iterate over all nodes in the original element
                foreach (var newNodes in toAdd.NonRecursiveVariations(lengthOfVariations))
                {
                    var orig = new XElement(referenceElement);

                    IEnumerable<ExpectedValue> expectedNodes = Helpers.ProcessNodes(calculateExpectedValues(orig, startPos, newNodes)).ToList();

                    // Add node on the expected place
                    XNode n = orig.FirstNode;
                    for (int position = 0; position < startPos; position++)
                    {
                        n = n.NextNode;
                    }

                    if (runWithEvents)
                    {
                        eHelper = new EventsHelper(orig);
                    }
                    testedFunction(n, newNodes);

                    // Node Equals check
                    TestLog.Compare(expectedNodes.EqualAll(orig.Nodes(), XNode.EqualityComparer), "constructed != added :: nodes Deep equals");

                    // release nodes
                    orig.RemoveAll();
                }
            }
        }
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:46,代码来源:AddNodeBeforeAfterBase.cs

示例13: DeleteXmlByYear

        public DateTime DeleteXmlByYear(XElement xelement, DateTime datetime)
        {
            if (this.EditState == TEditState.esEdit)
            {
                if (xelement != null && xelement.Descendants("DateTime").Count() >0)
                {
                    int year = DateTime.Now.AddYears(-1).Year;
                    IEnumerable<XElement> NodeByYear = xelement.Descendants("DateTime")
                        .Where(p => Convert.ToDateTime(p.Attribute("EndOfMonth").Value).Year >= year);
                    if (NodeByYear != null  && NodeByYear.Count()!= 0)
                    {
                        NodeByYear.Remove();
                        //存在去年的数据,则只要生成去年和今年的数据即可
                        datetime = new DateTime(year, 1, 1);
                    }
                }

            }
            else if (this.EditState == TEditState.esNew)
            {
                xelement.RemoveAll();
            }
            return datetime;
        }
开发者ID:unicloud,项目名称:AFRP,代码行数:24,代码来源:BaseXml.cs

示例14: WriteTo

        public void WriteTo(XElement element)
        {
            if (element != null)
            {
                element.RemoveAll();

                lock (AudioPluginViewSettings.lockObj)
                {
                    OnWriteTo(element);
                }
            }
        }
开发者ID:UnaNancyOwen,项目名称:Kinect-Studio-Sample,代码行数:12,代码来源:AudioPluginViewSettings.cs

示例15: ElementRemove

                /// <summary>
                /// Validates remove methods on elements.
                /// </summary>
                /// <param name="contextValue"></param>
                /// <returns></returns>
                //[Variation(Desc = "ElementRemove")]
                public void ElementRemove()
                {
                    XElement e =
                        new XElement("x",
                            new XAttribute("a1", 1),
                            new XAttribute("a2", 2),
                            new XText("abcd"),
                            10,
                            new XElement("y",
                                new XComment("comment")),
                            new XElement("z"));

                    Validate.Count(e.DescendantNodesAndSelf(), 5);
                    Validate.Count(e.Attributes(), 2);

                    e.RemoveAll();
                    Validate.Count(e.DescendantNodesAndSelf(), 1);
                    Validate.Count(e.Attributes(), 0);

                    // Removing all from an already empty one.
                    e.RemoveAll();
                    Validate.Count(e.DescendantNodesAndSelf(), 1);
                    Validate.Count(e.Attributes(), 0);
                }
开发者ID:johnhhm,项目名称:corefx,代码行数:30,代码来源:SDMElement.cs


注:本文中的System.Xml.Linq.XElement.RemoveAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。