本文整理匯總了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);
}
}
}
示例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);
}
}
}
示例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);
}
}
}
示例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);
}
示例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);
}
}
}
示例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);
}
}
}
示例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);
}
示例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));
}
}
示例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);
}
}
示例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);
}
示例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);
}
}
}
示例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();
}
}
}
示例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;
}
示例14: WriteTo
public void WriteTo(XElement element)
{
if (element != null)
{
element.RemoveAll();
lock (AudioPluginViewSettings.lockObj)
{
OnWriteTo(element);
}
}
}
示例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);
}