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


C# XElement.DescendantNodes方法代碼示例

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


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

示例1: Style

 public Style(XElement xElement)
 {
     foreach (XElement descendant in xElement.DescendantNodes())
     {
         switch (descendant.Name.ToString())
         {
             case "IconStyle":
                 this.iconStyle = new IconStyle(descendant);
                 break;
             //case "LabelStyle":
             //    this.labelStyle = new LabelStyle(descendant);
             //    break;
             //case "LineStyle":
             //    this.lineStyle = new LineStyle(descendant);
             //    break;
             //case "PolyStyle":
             //    this.polyStyle = new PolyStyle(descendant);
             //    break;
             //case "BalloonStyle":
             //    this.balloonStyle = new BalloonStyle(descendant);
             //    break;
             //case "ListStyle":
             //    this.listStyle = new ListStyle(descendant);
             //    break;
         }
     }
 }
開發者ID:AlphaTangoIndia,項目名稱:excel2earth,代碼行數:27,代碼來源:Style.cs

示例2: ChildNodeNavigation

        static void ChildNodeNavigation()
        {
            var bench = new XElement("bench",
                            new XElement("toolbox",
                                new XElement("handtool", "Hammer"),
                                new XElement("handtool", "Rasp")
                            ),
                            new XElement("toolbox",
                                new XElement("handtool", "Saw"),
                                new XElement("powertool", "Nailgun")
                            ),
                            new XComment("Be careful with the nailgun")
                        );

            foreach (XNode node in bench.Nodes())
            {
                Console.WriteLine(node.ToString(SaveOptions.DisableFormatting) + ".");
            }

            // Retrieving elements
            foreach (XElement e in bench.Elements())
            {
                Console.WriteLine(e.Name + "=" + e.Value);
            }

            foreach (var tool in bench.Elements("toolbox").Elements("handtool"))
            {
                Console.WriteLine("tool: {0} = {1}", tool.Name, tool.Value);
            }

            // query
            IEnumerable<string> query =
                from toolbox in bench.Elements()
                where toolbox.Elements().Any(tool => tool.Value == "Nailgun")
                select toolbox.Value;
            PrintQueryResult(query);

            query =
                from toolbox in bench.Elements()
                from tool in toolbox.Elements()
                where tool.Name == "handtool"
                select tool.Value;
            PrintQueryResult(query);

            // counts
            int x = bench.Elements("toolbox").Count();
            int y = bench.Elements().Where(e => e.Name == "toolbox").Count();
            Console.WriteLine("count1: {0}, count2: {1}", x, y);

            // Retrieving descendants
            Console.WriteLine(bench.Descendants("handtool").Count());

            foreach (XNode node in bench.DescendantNodes())
            {
                Console.WriteLine(node.ToString(SaveOptions.DisableFormatting));
            }
        }
開發者ID:kasicass,項目名稱:kasicass,代碼行數:57,代碼來源:Program.cs

示例3: Option

 public Option(XElement sourceElement, Service service)
 {
     Service = service;
       _texts = sourceElement
     .DescendantNodes()
     .OfType<XText>()
     .Where(t => !string.IsNullOrWhiteSpace(t.Value))
     .Select(t => t.Value.Trim())
     .ToList();
 }
開發者ID:garmstrong11,項目名稱:RFQBuddy,代碼行數:10,代碼來源:Option.cs

示例4: DecodeTree

        // ======================= Вспомогательные процедуры
        public static XElement DecodeTree(XElement tree)
        {
            // Найдем литералы и сделаем таблицу литералов
            int[] literals = tree.DescendantNodes()
                .Where(nd => nd.NodeType == System.Xml.XmlNodeType.Text)
                .Cast<XText>()
                .Where(xt => { int val; return Int32.TryParse(xt.Value, out val); })
                .Select(xt => Int32.Parse(xt.Value))
                .Distinct()
                .ToArray();
            var lit_dict = RelationalEngine.GetLiteralsForIds(literals).ToDictionary(li => li.literalid);

            return DecTree(tree, lit_dict);
        }
開發者ID:agmarchuk,項目名稱:Turgunda,代碼行數:15,代碼來源:Engine.cs

示例5: AddBatchMethod

        public static XElement AddBatchMethod(XElement batch, string cmd, params object[] batchContent)
        {
            XElement method = new XElement("Method",
                            new XAttribute("ID", batch.DescendantNodes().Count() + 1),
                            new XAttribute("Cmd", cmd));
            batch.Add(method);

            if (batchContent != null)
            {
                foreach (var item in batchContent)
                {
                    method.Add(item);
                }
            }

            return method;
        }
開發者ID:Titaye,項目名稱:SLExtensions,代碼行數:17,代碼來源:SharepointSite.cs

示例6: FixWhitespace

        private void FixWhitespace(XElement xmlElement)
        {
            foreach (var node in xmlElement.DescendantNodes())
            {
                XElement el = node as XElement;
                if (el != null)
                {
                    FixWhitespace(el);
                    continue;
                }

                XText txt = node as XText;
                if (txt != null)
                {
                    txt.Value = FixWhitespace(txt.Value);
                }
            }
        }
開發者ID:CharlieBP,項目名稱:NLog,代碼行數:18,代碼來源:NLogApiMerger.cs

示例7: Create

		public static AmbientColor Create (XElement element, Dictionary<string, Cairo.Color> palette)
		{
			var result = new AmbientColor ();
			foreach (var node in element.DescendantNodes ()) {
				if (node.NodeType == System.Xml.XmlNodeType.Element) {
					var el = (XElement)node;
					switch (el.Name.LocalName) {
					case "name":
						result.Name = el.Value;
						break;
					default:
						result.Colors.Add (Tuple.Create (el.Name.LocalName, ColorScheme.ParsePaletteColor (palette, el.Value)));
						break;
					}
				}
			}
			
			return result;
		}
開發者ID:RainsSoft,項目名稱:playscript-monodevelop,代碼行數:19,代碼來源:AmbientColor.cs

示例8: ExtractFeatureElements

        private Dictionary<string, string> ExtractFeatureElements(XElement layerElement)
        {
            try
            {
                var feature = new Dictionary<string, string>();
                var elements = layerElement.DescendantNodes().OfType<XElement>();

                foreach (var element in elements)
                {
                    if (!element.HasElements && !element.Name.LocalName.Equals("coordinates"))
                        feature.Add(element.Name.LocalName, element.Value);
                }

                return feature;
            }
            catch (Exception)
            {
                throw new ApplicationException("Error creating features");
            }
        }
開發者ID:pauldendulk,項目名稱:Mapsui,代碼行數:20,代碼來源:GmlGetFeatureInfoParser.cs

示例9: HandleExtendedParameters

 public override void HandleExtendedParameters(XElement extendedParameters)
 {
     foreach (XElement param in extendedParameters.DescendantNodes())
     {
         if(param.Name == "ParticleSystem")
             if (param.Attribute("name") != null)
             {
                 if (!emitters.ContainsKey(param.Attribute("name").Value))
                 {
                     if (param.Attribute("active") != null)
                     {
                         emitters.Add(param.Attribute("name").Value, bool.Parse(param.Attribute("active").Value));
                     }
                     else
                     {
                         emitters.Add(param.Attribute("name").Value, true);
                     }
                 }
             }
     }
 }
開發者ID:Gartley,項目名稱:ss13remake,代碼行數:21,代碼來源:ParticleSystemComponent.cs

示例10: AllInclusiveValue

 private string AllInclusiveValue(XElement ele)
 {
     bool ignoreNext = false;
     return string.Join(" ", ele.DescendantNodes().Select(x =>
     {
         if (ignoreNext)
         {
             ignoreNext = false;
             return null;
         }
         if (x is XText) return ((XText) x).Value;
         if (x is XElement)
         {
             var xele = (XElement) x;
             if (xele.IsEmpty) return "<" + xele.Name + "/>";
             ignoreNext = true;
             return "<" + xele.Name + ">" + AllInclusiveValue(xele) + "</" + xele.Name + ">";
         }
         return null;
     }).Where(x => x != null));
 }
開發者ID:Ancestry,項目名稱:Daisy,代碼行數:21,代碼來源:CommentDocumentation.cs

示例11: processMenuElement

 private object processMenuElement(XElement theElement, string theDefault, MenuItemClick delg)
 {
     if (theElement.Name == Common.MenuItem)
     {
         MenuItem theItem = new MenuItem();
         theItem.Header = theElement.GetAttribute("text");
         string action = theElement.GetAttribute(Common.MenuAction);
         theItem.Tag = action;
         if (action == theDefault)
         {
             theItem.FontWeight = FontWeights.Bold;
         }
         theItem.Click += new RoutedEventHandler(delg);
         /*
         theElement.GetAttribute("clientAction")
         if (Common.boolValue(theElement.GetAttribute("checked")))
             theItem.Checked = true;
         if (theItem.Action == theDefault)
             theItem.DefaultItem = true;
         */
         return theItem;
     }
     else if (theElement.Name == Common.ProcessSeparator)
     {
         Separator s = new Separator();
         return s;
     }
     else//sub menu
     {
         MenuItem theItem = new MenuItem();
         theItem.Header = theElement.Attribute("name").Value;
         foreach(XElement child in theElement.DescendantNodes() )
         {
             theItem.Items.Add(processMenuElement((XElement)child, theDefault, delg));
         }
         return theItem;
     }
 }
開發者ID:expanz,項目名稱:expanz-Microsoft-XAML-SDKs,代碼行數:38,代碼來源:ControlHarness.WPF.cs

示例12: WriteXmlDocParameter

 static void WriteXmlDocParameter(IXmlDocOutput output, XElement xml)
 {
     foreach (var elem in xml.DescendantNodes()) {
         if (elem is XText)
             output.Write(XmlDocRenderer.whitespace.Replace(((XText)elem).Value, " "), TextTokenType.XmlDocSummary);
         else if (elem is XElement) {
             var xelem = (XElement)elem;
             switch (xelem.Name.ToString().ToUpperInvariant()) {
             case "SEE":
                 var cref = xelem.Attribute("cref");
                 if (cref != null)
                     output.Write(XmlDocRenderer.GetCref((string)cref), TextTokenType.XmlDocToolTipSeeCref);
                 var langword = xelem.Attribute("langword");
                 if (langword != null)
                     output.Write(((string)langword).Trim(), TextTokenType.XmlDocToolTipSeeLangword);
                 break;
             case "PARAMREF":
                 var nameAttr = xml.Attribute("name");
                 if (nameAttr != null)
                     output.Write(((string)nameAttr).Trim(), TextTokenType.XmlDocToolTipParamRefName);
                 break;
             case "BR":
             case "PARA":
                 output.WriteNewLine();
                 break;
             default:
                 break;
             }
         }
         else
             output.Write(elem.ToString(), TextTokenType.XmlDocSummary);
     }
 }
開發者ID:BahNahNah,項目名稱:dnSpy,代碼行數:33,代碼來源:SimpleHighlighter.cs

示例13: ExpandTemplates

        static void ExpandTemplates(XDocument doc, List<XElement> templates)
        {
            foreach (var inheritMarker in doc.Descendants("inherittemplate").ToList())
            {
                var name = inheritMarker.Attribute("name").Value;
                var replacement = inheritMarker.Attribute("replacement")?.Value;

                var template = templates.Single(t => t.Attribute("name").Value == name);

                var clonedTemplate = new XElement(template);

                if (replacement != null)
                {
                    foreach (var attribute in clonedTemplate.Descendants().Attributes())
                    {
                        attribute.Value = attribute.Value.Replace(name, replacement);
                    }

                    foreach (var text in clonedTemplate.DescendantNodes().OfType<XText>())
                    {
                        text.Value = text.Value.Replace(name, replacement);
                    }
                }


                inheritMarker.ReplaceWith(clonedTemplate.Elements());
            }
        }
開發者ID:fengweijp,項目名稱:Win2D,代碼行數:28,代碼來源:Program.cs

示例14: ResolveAssertContent

        private static void ResolveAssertContent(XElement xAssert, Assert assert, XmlNamespaceManager nsManager)
        {
            List<string> diagnostics = new List<string>();
            List<bool> diagnosticsIsValueOf = new List<bool>();

            XName nameElement = XName.Get("name", Constants.ISONamespace);
            XName valueofElement = XName.Get("value-of", Constants.ISONamespace);

            StringBuilder sbMessage = new StringBuilder();
            foreach (XNode node in xAssert.DescendantNodes())
            {
                if (!(node is XElement))
                {
                    sbMessage.Append(node.ToString());
                }
                else
                {
                    XElement xEle = (XElement)node;

                    // resolve name, value-of
                    string xpathDiagnostic = null;
                    if (xEle.Name == nameElement)
                    {
                        diagnosticsIsValueOf.Add(false);
                        xpathDiagnostic = "name()";
                        XAttribute xPath = xEle.Attribute(XName.Get("path"));
                        if (xPath != null)
                        {
                            xpathDiagnostic = String.Format(String.Format("name({0})", xPath.Value));
                        }
                    }
                    else if (xEle.Name == valueofElement)
                    {
                        diagnosticsIsValueOf.Add(true);
                        xpathDiagnostic = xEle.Attribute(XName.Get("select")).Value;
                    }

                    if (xpathDiagnostic != null)
                    {
                        // get collection index
                        int index = diagnostics.IndexOf(xpathDiagnostic);
                        if (index < 0)
                        {
                            diagnostics.Add(xpathDiagnostic);
                            index = diagnostics.Count - 1;
                        }

                        sbMessage.Append("{");
                        sbMessage.Append(index);
                        sbMessage.Append("}");
                        index++;
                    }
                }
            }

            assert.Message = sbMessage.ToString();
            assert.Diagnostics = diagnostics.ToArray();
            assert.DiagnosticsIsValueOf = diagnosticsIsValueOf.ToArray();
        }
開發者ID:xpekatt,項目名稱:SchemaTron,代碼行數:59,代碼來源:SchemaDeserializer.cs

示例15: Create

		internal static ChunkStyle Create (XElement element, Dictionary<string, HslColor> palette)
		{
			var result = new ChunkStyle ();

			foreach (var node in element.DescendantNodes ()) {
				if (node.NodeType == System.Xml.XmlNodeType.Element) {
					var el = (XElement)node;
					switch (el.Name.LocalName) {
					case "name":
						result.Name = el.Value;
						break;
					case "fore":
						result.Foreground = ColorScheme.ParsePaletteColor (palette, el.Value);
						break;
					case "back":
						result.Background = ColorScheme.ParsePaletteColor (palette, el.Value);
						break;
					case "weight":
						Xwt.Drawing.FontWeight weight;
						if (!Enum.TryParse<Xwt.Drawing.FontWeight> (el.Value, true, out weight)) 
							throw new InvalidDataException (el.Value + " is no valid text weight values are: " + string.Join (",", Enum.GetNames (typeof(Xwt.Drawing.FontWeight))) );
						result.FontWeight = weight;
						break;
					case "style":
						Xwt.Drawing.FontStyle style;
						if (!Enum.TryParse<Xwt.Drawing.FontStyle> (el.Value, true, out style)) 
							throw new InvalidDataException (el.Value + " is no valid text weight values are: " + string.Join (",", Enum.GetNames (typeof(Xwt.Drawing.FontStyle))) );
						result.FontStyle = style;
						break;
					default:
						throw new InvalidDataException ("Invalid element in text color:" + el.Name);
					}
				}
			}

			return result;
		}
開發者ID:pabloescribanoloza,項目名稱:monodevelop,代碼行數:37,代碼來源:ChunkStyle.cs


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