當前位置: 首頁>>代碼示例>>C#>>正文


C# XElement.RemoveNodes方法代碼示例

本文整理匯總了C#中System.Xml.Linq.XElement.RemoveNodes方法的典型用法代碼示例。如果您正苦於以下問題:C# XElement.RemoveNodes方法的具體用法?C# XElement.RemoveNodes怎麽用?C# XElement.RemoveNodes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Xml.Linq.XElement的用法示例。


在下文中一共展示了XElement.RemoveNodes方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Main

 static void Main(string[] args)
 {
     var input = XDocument.Load("Config.xml");   
     var output = new XDocument(input.Declaration);
     var outputRoot = new XElement(input.Root);
     outputRoot.RemoveNodes();
     output.Add(outputRoot);
     foreach (var node in input.Descendants().Where(n => !n.Elements().Any()))
     {
         var newNode = new XElement(node.Name);
         var p = node.Parent;
         int level = 0;
         while (p != input.Root)
         {
             string attrName;
             if (level == 0)
             {
                 attrName = "parent";
             }
             else
             {
                 attrName = string.Join("", Enumerable.Repeat("grand",level));
             }
             newNode.SetAttributeValue(attrName, p.Name);
             level++;
             p = p.Parent;
         }
         newNode.Add(node.Attributes());
         outputRoot.Add(newNode);
     }
     Console.WriteLine(output);
     output.Save("output.xml");
     Console.Read();
 }
開發者ID:ewasow,項目名稱:learning-cs,代碼行數:34,代碼來源:Program.cs

示例2: NestContext

		internal static void NestContext(XElement importSettingsProperty,
			string scriptureBaseDir,
			IDictionary<string, SortedDictionary<string, byte[]>> classData,
			Dictionary<string, string> guidToClassMapping)
		{
			if (importSettingsProperty == null)
				return;
			var importSettings = importSettingsProperty.Elements().ToList();
			if (!importSettings.Any())
				return;

			var root = new XElement(SharedConstants.ImportSettings);

			foreach (var importSettingObjSur in importSettings)
			{
				var styleGuid = importSettingObjSur.Attribute(SharedConstants.GuidStr).Value.ToLowerInvariant();
				var className = guidToClassMapping[styleGuid];
				var importSetting = Utilities.CreateFromBytes(classData[className][styleGuid]);

				CmObjectNestingService.NestObject(false, importSetting,
												  classData,
												  guidToClassMapping);

				root.Add(importSetting);
			}

			FileWriterService.WriteNestedFile(Path.Combine(scriptureBaseDir, SharedConstants.ImportSettingsFilename), root);

			importSettingsProperty.RemoveNodes();
		}
開發者ID:gmartin7,項目名稱:flexbridge,代碼行數:30,代碼來源:ImportSettingsBoundedContextService.cs

示例3: NestContext

		internal static void NestContext(XElement archivedDraftsProperty,
			string scriptureBaseDir,
			IDictionary<string, SortedDictionary<string, byte[]>> classData,
			Dictionary<string, string> guidToClassMapping)
		{
			if (archivedDraftsProperty == null)
				return;
			var drafts = archivedDraftsProperty.Elements().ToList();
			if (!drafts.Any())
				return;

			foreach (var draftObjSur in drafts)
			{
				var root = new XElement(SharedConstants.ArchivedDrafts);
				var draftGuid = draftObjSur.Attribute(SharedConstants.GuidStr).Value.ToLowerInvariant();
				var className = guidToClassMapping[draftGuid];
				var draft = Utilities.CreateFromBytes(classData[className][draftGuid]);

				CmObjectNestingService.NestObject(false, draft,
					classData,
					guidToClassMapping);

				root.Add(draft);
				FileWriterService.WriteNestedFile(Path.Combine(scriptureBaseDir, SharedConstants.Draft + "_" + draftGuid.ToLowerInvariant() + "." + SharedConstants.ArchivedDraft), root);
			}

			archivedDraftsProperty.RemoveNodes();
		}
開發者ID:gmartin7,項目名稱:flexbridge,代碼行數:28,代碼來源:ArchivedDraftsBoundedContextService.cs

示例4: NodeParent

                /// <summary>
                /// Tests the Parent property on Node.
                /// </summary>
                /// <param name="context"></param>
                /// <returns></returns>
                //[Variation(Desc = "NodeParent")]
                public void NodeParent()
                {
                    // Only elements are returned as parents from the Parent property.
                    // Documents are not returned.
                    XDocument document = new XDocument();

                    XNode[] nodes = new XNode[]
                        {
                            new XComment("comment"),
                            new XElement("element"),
                            new XProcessingInstruction("target", "data"),
                            new XDocumentType("name", "publicid", "systemid", "internalsubset")
                        };

                    foreach (XNode node in nodes)
                    {
                        Validate.IsNull(node.Parent);
                        document.Add(node);
                        Validate.IsReferenceEqual(document, node.Document);
                        // Parent element is null.
                        Validate.IsNull(node.Parent);
                        document.RemoveNodes();
                    }

                    // Now test the cases where an element is the parent.
                    nodes = new XNode[]
                        {
                            new XComment("abcd"),
                            new XElement("nested"),
                            new XProcessingInstruction("target2", "data2"),
                            new XText("text")
                        };

                    XElement root = new XElement("root");
                    document.ReplaceNodes(root);

                    foreach (XNode node in nodes)
                    {
                        Validate.IsNull(node.Parent);

                        root.AddFirst(node);

                        Validate.IsReferenceEqual(node.Parent, root);

                        root.RemoveNodes();
                        Validate.IsNull(node.Parent);
                    }
                }
開發者ID:johnhhm,項目名稱:corefx,代碼行數:54,代碼來源:SDMNode.cs

示例5: MergeTemplatesWithConfig

        public XElement MergeTemplatesWithConfig(XElement configAsXElement)
        {
            var newConfifAsXElement = new XElement(configAsXElement);
            newConfifAsXElement.RemoveNodes();

            configAsXElement.Elements().ForEach(e=>
                                                    {
                                                        if (e.Name.LocalName != "build-type")
                                                        {
                                                            newConfifAsXElement.Add(e);
                                                        }
                                                    });

            var buildTypes = configAsXElement.Elements("build-type");
            buildTypes.ForEach(bt=>
                                   {
                                       var btElement = new XElement(bt);
                                       btElement.RemoveNodes();
                                       bt.Elements().ForEach(bte=> { if(bte.Name.LocalName!="settings")btElement.Add(bte);});
                                       var settings = bt.Element("settings");
                                       var template = settings.AttributeValueOrDefault("ref",null);
                                       if(template!=null)
                                       {
                                           if(_dictionary.ContainsKey(template))
                                           {
                                               var mergedSettingsXElement = Merge(settings, _dictionary[template]);
                                               btElement.Add(mergedSettingsXElement);
                                           }
                                           else
                                            throw new Exception("Could not find template "+template);
                                       }
                                       else
                                           btElement.Add(settings);

                                       newConfifAsXElement.Add(btElement);
                                   }
                );
            return newConfifAsXElement;
        }
開發者ID:sankalpsaxena81,項目名稱:SequenceDiagramGeneratorForTeamCityProjects,代碼行數:39,代碼來源:TemplateMerger.cs

示例6: Alphabetize

 public static XElement Alphabetize(XElement el)
 {
     Comparison<XElement> comparison = new Comparison<XElement>(Program.Compare);
     List<XAttribute> content = new List<XAttribute>(el.Attributes());
     List<XElement> list2 = new List<XElement>(el.Elements());
     content.Sort((x, y) => string.CompareOrdinal(x.Name.ToString(), y.Name.ToString()));
     list2.Sort(comparison);
     XElement element = new XElement(el.Name);
     element.Add(content);
     element.Add(list2);
     el.RemoveAttributes();
     el.RemoveNodes();
     el.Add(new object[] { content, list2 });
     if (el.HasElements)
     {
         foreach (XElement element2 in el.Elements())
         {
             Alphabetize(element2);
         }
     }
     return el;
 }
開發者ID:NuzzIndustries,項目名稱:ProbesvZealot2StatTransfer,代碼行數:22,代碼來源:Program.cs

示例7: InternalProcess

		/// <summary>
		/// 	Internals the process.
		/// </summary>
		/// <remarks>
		/// </remarks>
		protected override void InternalProcess() {
			foreach (var t in Context.Themas.Values) {
				foreach (var item in t.ImportedThemaItems.Union(t.SelfThemaItems)) {
					var key = item.Key;
					var x = new XElement(item.Value);
					XElement s = null;
					if (t.SelfThemaItemsSets.ContainsKey(key)) {
						s = t.SelfThemaItemsSets[key];
					}
					else if (t.ImportedThemaItemsSets.ContainsKey(key)) {
						s = t.ImportedThemaItemsSets[key];
					}
					if (null != s) {
						x.RemoveNodes();
						x.Add(s.Nodes());
						foreach (var a in s.Attributes()) {
							x.SetAttributeValue(a.Name, a.Value);
						}
					}
					if (t.ImportedThemaItemsExtensions.ContainsKey(key)) {
						foreach (var e in t.ImportedThemaItemsExtensions[key]) {
							x.Add(e.Nodes());
							foreach (var a in e.Attributes()) {
								x.SetAttributeValue(a.Name, a.Value);
							}
						}
					}
					if (t.SelfThemaItemsExtensions.ContainsKey(key)) {
						x.Add(t.SelfThemaItemsExtensions[key].Nodes());
						foreach (var a in t.SelfThemaItemsExtensions[key].Attributes()) {
							x.SetAttributeValue(a.Name, a.Value);
						}
					}
					t.Items[key] = x;
				}
			}
		}
開發者ID:comdiv,項目名稱:qorpent.themas,代碼行數:42,代碼來源:ResolveElementsStep.cs

示例8: XLinq66

        public void XLinq66()
        {
            XElement elem = new XElement("customer",
                                         "this is an XElement",
                                         new XAttribute("id", "abc"));
            Console.WriteLine("Original element {0}", elem);

            elem.RemoveNodes();
            Console.WriteLine("Updated element {0}", elem);
        }
開發者ID:NamrataGanatra,項目名稱:LinqTest,代碼行數:10,代碼來源:LinqToXmlSamples.cs

示例9: copyWithoutChildren

 private static XElement copyWithoutChildren(XElement element)
 {
     var newElement = new XElement(element);
     newElement.RemoveNodes();
     return newElement;
 }
開發者ID:ewasow,項目名稱:learning-cs,代碼行數:6,代碼來源:Program+-+Copy.cs

示例10: ProcessElements

        private XElement ProcessElements(IEnumerable<ItemRepeaterElement> itemRepeaterElements, DataReader dataReader, XElement start, XElement parent, int index, out ICollection<XElement> elementsBeforeNestedRepeaters, bool nested = false)
        {
            XElement result = null;
            XElement previous = start;
            ICollection<XElement> tempElementsBeforeItemRepeaters = new List<XElement>();
            foreach (var itemRepeaterElement in itemRepeaterElements)
            {
                if (!itemRepeaterElement.IsVisible || itemRepeaterElement.IsItemIf || itemRepeaterElement.IsEndItemIf)
                {
                    continue;
                }                
                if (itemRepeaterElement.IsItemHtmlContent)
                {
                    result = HtmlContentProcessor.MakeHtmlContentProcessed(itemRepeaterElement.XElement, dataReader.ReadText(itemRepeaterElement.Expression), true);
                }
                else if (itemRepeaterElement.IsIndex)
                {
                    result = DocxHelper.CreateTextElement(itemRepeaterElement.XElement,
                                                          itemRepeaterElement.XElement.Parent,
                                                          index.ToString(CultureInfo.CurrentCulture),
                                                          !nested
                        );
                }
                else if (itemRepeaterElement.IsItem && itemRepeaterElement.HasExpression)
                {
                    result = DocxHelper.CreateTextElement(itemRepeaterElement.XElement,
                                                          itemRepeaterElement.XElement.Parent,
                                                          dataReader.ReadText(itemRepeaterElement.Expression),
                                                          !nested
                        );
                }
                else
                {
                    var element = new XElement(itemRepeaterElement.XElement);
                    element.RemoveNodes();
                    result = element;
                    if (itemRepeaterElement.HasElements)
                    {
                        ICollection<XElement> bisectNestedElements = new List<XElement>();
                        this.ProcessElements(itemRepeaterElement.Elements, dataReader, null, result, index, out bisectNestedElements, true);
                        if (bisectNestedElements.Count != 0)
                        {
                            tempElementsBeforeItemRepeaters.Add(bisectNestedElements.ElementAt(0));
                        }
                    }
                    else
                    {
                        element.Value = itemRepeaterElement.XElement.Value;
                    }
                }

                if (previous != null)
                {
                    previous.AddAfterSelf(result);
                    previous = result;
                }
                else
                {
                    parent.Add(result);
                }
                if (itemRepeaterElement.IsBeforeNestedRepeater)
                {
                    tempElementsBeforeItemRepeaters.Add(result);
                }
            }
            elementsBeforeNestedRepeaters = tempElementsBeforeItemRepeaters;
            return result;
        }
開發者ID:koZZZdya,項目名稱:TsSoft.Docx.TemplateEngine,代碼行數:68,代碼來源:ItemRepeaterParser.cs

示例11: setValueElement

 private static void setValueElement(XElement element, string value)
 {
     element.RemoveNodes();
     XElement newElement = new XElement("valueElement", new XAttribute("value", value));
     element.Add(newElement);
 }
開發者ID:nexus49,項目名稱:grado,代碼行數:6,代碼來源:Configuration.cs

示例12: SortHeader

		private static void SortHeader(XElement header)
		{
			// Has three optional elements: description, ranges, and fields.
			// Put them in this order, if present: description, ranges, and fields.
			var description = header.Element("description");
			if (description != null)
			{
				description.Remove();
			}
			var ranges = header.Element("ranges");
			if (ranges != null)
			{
				ranges.Remove();
			}
			var fields = header.Element("fields");
			if (fields != null)
			{
				fields.Remove();
			}
			var leftovers = header.Elements().ToList();

			header.RemoveNodes();

			if (description != null)
			{
				SortMultiformElement(description);
				header.Add(description);
			}
			if (ranges != null)
			{
				SortRanges(ranges);
				header.Add(ranges);
			}
			if (fields != null)
			{
				var sortedFields = SortFields(fields, "tag");
				header.Add(fields);
				foreach (var field in sortedFields.Values)
				{
					fields.Add(field);
				}
			}

			foreach (var leftover in leftovers)
			{
				header.Add(leftover);
			}
		}
開發者ID:JohnThomson,項目名稱:libpalaso,代碼行數:48,代碼來源:LiftSorter.cs

示例13: ProcessElements

        private XElement ProcessElements(IEnumerable<RepeaterElement> elements, DataReader dataReader, XElement start, XElement parent, int index, ref XElement endIfElement, ref XElement nestedRepeaterEndElement, ref XElement currentEndItemTable, bool nested = false)
        {
            XElement result = null;
            XElement previous = start;
            //if ((parent != null) && (!parent.Name.Equals(WordMl.TableCellName)))
            //{
                elements = elements.Where(el => !this.IsItemRepeaterElement(el.XElement)).ToList();
            //}            
            foreach (var repeaterElement in elements )//elements.Where(el => !this.IsItemRepeaterElement(el.XElement)).ToList())
            { 
                if (nestedRepeaterEndElement != null)
                {
                    if (repeaterElement.XElement.Equals(nestedRepeaterEndElement))
                    {
                        nestedRepeaterEndElement = null;
                    }
                    continue;
                }
                if (currentEndItemTable != null)
                {                    
                    if (repeaterElement.XElement.Equals(currentEndItemTable))
                    {
                        currentEndItemTable = null;
                    }
                    continue;
                }
                if (repeaterElement.IsEndItemIf /*&& repeaterElement.XElement.Equals(endIfElement)*/)
                {
                    //endIfElement = null;
                    if (repeaterElement.XElement.Equals(endIfElement))
                    {
                        endIfElement = null;
                    }
                    continue;
                }
                if ((endIfElement != null) && !repeaterElement.XElement.Name.Equals(WordMl.ParagraphName))
                {
                    continue;                    
                }
                if (repeaterElement.IsItemIf)
                {
                    this.ProcessItemIfElement(repeaterElement, dataReader, ref endIfElement);
                    continue;                    
                }

                if (repeaterElement.IsItemTable)
                {
                    /*currentEndItemTable = RepeaterParser.FindEndTag(repeaterElement.XElement, "itemtable",
                                                                    "enditemtable");*/
                    currentEndItemTable = repeaterElement.EndTag;
                }
                /*
                if (repeaterElement.IsEndItemTable /*|| (repeaterElement.XElement.Name.Equals(WordMl.TableName) && repeaterElement.XElement.Descendants().Any(el => el.IsSdt())))
                {
                    continue;                    
                }*/
                if (repeaterElement.IsItemHtmlContent)
                {
                    result = HtmlContentProcessor.MakeHtmlContentProcessed(repeaterElement.XElement, dataReader.ReadText(repeaterElement.Expression), true);                    
                }
                else if (repeaterElement.IsItemTable)
                {
                    result = ItemTableGenerator.ProcessItemTableElement(repeaterElement.StartTag, repeaterElement.EndTag,
                                                                        dataReader);
                    if (nested)
                    {
                        previous.AddAfterSelf(result);
                        previous = result;
                        result = null;                        
                    }                    
                }
                else if (repeaterElement.IsItemRepeater)
                {                                        
                    var itemRepeaterTag = new ItemRepeaterTag()
                        {
                            StartItemRepeater = repeaterElement.StartTag,
                            EndItemRepeater = repeaterElement.EndTag,
                            Source = repeaterElement.Expression                            
                        };                                       
                    var itemRepeaterGenerator = new ItemRepeaterGenerator();
                    previous = itemRepeaterGenerator.Generate(itemRepeaterTag,
                                                              dataReader.GetReaders(repeaterElement.Expression),
                                                              previous, parent, true);
                    result = null;
                    nestedRepeaterEndElement = repeaterElement.EndTag;
                }
                else if (repeaterElement.IsIndex)
                {
                    result = DocxHelper.CreateTextElement(repeaterElement.XElement, repeaterElement.XElement.Parent, index.ToString(CultureInfo.CurrentCulture));
                }
                else if (repeaterElement.IsItem && repeaterElement.HasExpression)
                {
                    result = DocxHelper.CreateTextElement(repeaterElement.XElement, repeaterElement.XElement.Parent, dataReader.ReadText(repeaterElement.Expression), dataReader.ReadAttribute(repeaterElement.Expression, "style"));                    
                }
                else
                {                    
                    var element = new XElement(repeaterElement.XElement);
                    element.RemoveNodes();
                    result = element;
                    if (repeaterElement.HasElements)
//.........這裏部分代碼省略.........
開發者ID:koZZZdya,項目名稱:TsSoft.Docx.TemplateEngine,代碼行數:101,代碼來源:RepeaterProcessor.cs

示例14: SortEntry

		private static void SortEntry(XElement entry)
		{
			var lexicalUnit = entry.Element("lexical-unit");
			if (lexicalUnit != null)
			{
				SortMultiformElement(lexicalUnit);
				lexicalUnit.Remove();
			}
			var citation = entry.Element("citation");
			if (citation != null)
			{
				SortMultiformElement(citation);
				citation.Remove();
			}

			var pronunciations = SortPronunciations(entry);
			var variants = SortVariantContents(entry);
			var sensesInFileOrder = SortSenseContent(entry, "sense");
			var sortedEtymologies = SortedEtymologies(entry);
			var notes = SortedNotes(entry);
			var sortedRelations = SortedRelations(entry);
			var sortedExtensibles = SortExtensibleWithField(entry);
			var leftovers = entry.Elements().ToList();

			entry.RemoveNodes();

			if (lexicalUnit != null)
				entry.Add(lexicalUnit);
			if (citation != null)
				entry.Add(citation);
			foreach (var pronunciation in pronunciations)
				entry.Add(pronunciation);
			foreach (var variant in variants)
				entry.Add(variant);
			foreach (var sense in sensesInFileOrder)
				entry.Add(sense);
			foreach (var note in notes.Values)
				entry.Add(note);
			foreach (var relation in sortedRelations.Values)
				entry.Add(relation);
			foreach (var etymology in sortedEtymologies.Values)
				entry.Add(etymology);
			RestoreSortedExtensibles(sortedExtensibles, entry);
			foreach (var leftover in leftovers)
				entry.Add(leftover);
		}
開發者ID:JohnThomson,項目名稱:libpalaso,代碼行數:46,代碼來源:LiftSorter.cs

示例15: SerializeToXml

        /// <summary>
        /// Serializes the annotation as XML to the body of hte given element.
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="annotation"></param>
        /// <param name="element"></param>
        XElement SerializeToXml(XObject obj, object annotation, XElement element)
        {
            Contract.Requires<ArgumentNullException>(obj != null);
            Contract.Requires<ArgumentNullException>(annotation != null);
            Contract.Requires<ArgumentNullException>(element != null);

            // configure element
            element.SetAttributeValue(NX_FORMAT, NX_FORMAT_XML);
            element.SetAttributeValue(NX_TYPE, annotation.GetType().FullName + ", " + annotation.GetType().Assembly.GetName().Name);
            element.RemoveNodes();

            // serialize anntation into body
            using (var wrt = element.CreateWriter())
            {
                wrt.WriteWhitespace(""); // fixes a bug in XmlSerializer that tries to WriteStartDocument

                if (annotation is ISerializableAnnotation)
                {
                    element.Add(((ISerializableAnnotation)annotation).Serialize(this));
                }
                else if (annotation is IXmlSerializable)
                {
                    var srs = GetXmlSerializer(annotation.GetType());
                    var ens = new XmlSerializerNamespaces();
                    ens.Add("", "");
                    srs.Serialize(wrt, annotation, ens);
                }
                else if (annotation.GetType().GetCustomAttribute<XmlRootAttribute>() != null)
                {
                    var srs = GetXmlSerializer(annotation.GetType());
                    var ens = new XmlSerializerNamespaces();
                    ens.Add("", "");
                    srs.Serialize(wrt, annotation, ens);
                }
                else
                    return null;
            }

            return element;
        }
開發者ID:nxkit,項目名稱:nxkit,代碼行數:46,代碼來源:AnnotationSerializer.cs


注:本文中的System.Xml.Linq.XElement.RemoveNodes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。