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


C# XElement.Nodes方法代碼示例

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


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

示例1: HandleXmlElement

        /// <inheritdoc/>
        protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, DocumentationCommentTriviaSyntax documentation, XmlNodeSyntax syntax, XElement completeDocumentation, Location[] diagnosticLocations)
        {
            if (completeDocumentation != null)
            {
                // We are working with an <include> element
                if (completeDocumentation.Nodes().OfType<XElement>().Any(element => element.Name == XmlCommentHelper.SummaryXmlTag))
                {
                    return;
                }

                if (completeDocumentation.Nodes().OfType<XElement>().Any(element => element.Name == XmlCommentHelper.InheritdocXmlTag))
                {
                    // Ignore nodes with an <inheritdoc/> tag in the included XML.
                    return;
                }
            }
            else
            {
                if (syntax != null)
                {
                    return;
                }

                if (documentation?.Content.GetFirstXmlElement(XmlCommentHelper.InheritdocXmlTag) != null)
                {
                    // Ignore nodes with an <inheritdoc/> tag.
                    return;
                }
            }

            foreach (var location in diagnosticLocations)
            {
                context.ReportDiagnostic(Diagnostic.Create(Descriptor, location));
            }
        }
開發者ID:NikolayIT,項目名稱:StyleCopAnalyzers,代碼行數:36,代碼來源:SA1604ElementDocumentationMustHaveSummary.cs

示例2: 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

示例3: _ProcessIteration

 private IEnumerable< XNode > _ProcessIteration(XElement element, XNode iterVal,
                                                string iterName)
 {
     XNode val = iterVal;
     IEnumerable< XNode > results = _Env.Call( () =>
                                                   {
                                                       /* Bind the iterator symbolic name to the current value */
                                                       if ( val is XContainer )
                                                           /* Nodeset value */
                                                       {
                                                           _Env.DefineNodesetSymbol(
                                                               iterName,
                                                               ( ( XContainer ) val ).
                                                                   Nodes() );
                                                       }
                                                       else /* Text value */
                                                       {
                                                           _Env.DefineTextSymbol( iterName,
                                                                                  val.
                                                                                      ToString
                                                                                      () );
                                                       }
                                                       /* Process loop body */
                                                       return _ProcessNodes( element.Nodes() );
                                                   } );
     return results;
 }
開發者ID:kascomp,項目名稱:CruiseControl.NET,代碼行數:27,代碼來源:ForEachProcessor.cs

示例4: IsSingleLineText

 static bool IsSingleLineText(XElement e)
 {
     if (e.HasAttributes) return false;
     foreach (XNode node in e.Nodes())
         if (!(node is XText) || ((XText)node).Value.Contains("\n")) return false;
     return true;
 }
開發者ID:jamesmaxwell,項目名稱:DesignPatternDemo,代碼行數:7,代碼來源:Converter.cs

示例5: PrintChildElement

 public static void PrintChildElement(XElement parent)
 {
     foreach (XElement item in parent.Nodes())
     {
         Console.WriteLine(item.Name);
     }
 }
開發者ID:shepherd44,項目名稱:SME_Window,代碼行數:7,代碼來源:XMLHelper.cs

示例6: AssertSerializedField

 private static void AssertSerializedField(XElement docNode, string value) {
     Assert.AreEqual(docNode.Nodes().Count(), 1);
     var fieldNode = docNode.Element("field");
     Assert.IsNotNull(fieldNode);
     Assert.AreEqual("one", fieldNode.Attribute("name").Value);
     Assert.AreEqual(value, fieldNode.Value);
 }
開發者ID:Jo1nes,項目名稱:SolrNet,代碼行數:7,代碼來源:SolrDictionarySerializerTests.cs

示例7: ElasticFromXElement

        /// <summary>
        /// Build an expando from an XElement
        /// </summary>
        /// <param name="el"></param>
        /// <returns></returns>
        public static ElasticObject ElasticFromXElement(XElement el)
        {
            var exp = new ElasticObject();

            if (!string.IsNullOrEmpty(el.Value))
                exp.InternalValue = el.Value;

            exp.InternalName = el.Name.LocalName;

            foreach (var a in el.Attributes())
                exp.CreateOrGetAttribute(a.Name.LocalName, a.Value);

            var textNode= el.Nodes().FirstOrDefault();
             if (textNode is XText)
                {
                    exp.InternalContent = textNode.ToString();
                }

            foreach (var c in el.Elements())
            {

                var child = ElasticFromXElement(c);
                child.InternalParent = exp;
                exp.AddElement(child);
            }
            return exp;
        }
開發者ID:arielbh,項目名稱:ElasticObject,代碼行數:32,代碼來源:DynamicExtensions.cs

示例8: InitiTunesTracks

        /// <summary>
        /// Get all available tracks from the given library
        /// </summary>
        private List<iTunesTrack> InitiTunesTracks()
        {
            XElement trackDictionary = new XElement("Tracks", from track in _itunesLibraryXDocument.Descendants("plist").Elements("dict").Elements("dict").Elements("dict")
                                                              select new XElement("track",
                                                                from key in track.Descendants("key")
                                                                select new XElement(((string)key).Replace(" ", ""), (string)(XElement)key.NextNode)));

            return (trackDictionary.Nodes().Select(track => new iTunesTrack()
            {
                Id = ((XElement)track).Element("TrackID").ToInt(0),
                Album = ((XElement)track).Element("Album").ToString(string.Empty),
                Artist = ((XElement)track).Element("Artist").ToString(string.Empty),
                AlbumArtist = ((XElement)track).Element("AlbumArtist").ToString(string.Empty),
                BitRate = ((XElement)track).Element("BitRate").ToInt(0),
                Comments = ((XElement)track).Element("Comments").ToString(string.Empty),
                Composer = ((XElement)track).Element("Composer").ToString(string.Empty),
                Genre = ((XElement)track).Element("Genre").ToString(string.Empty),
                Kind = ((XElement)track).Element("Kind").ToString(string.Empty),
                //To be able to have a + signs in the track location, we need to convert it to the correct HTML code before we use the UrlDecode
                Location = WebUtility.UrlDecode(((XElement)track).Element("Location").ToString(string.Empty).Replace(Constants.URI_LOCALHOST, string.Empty).Replace("+", "%2B")).Replace('/', Path.DirectorySeparatorChar),
                Name = ((XElement)track).Element("Name").ToString(string.Empty),
                PlayCount = ((XElement)track).Element("PlayCount").ToInt(0),
                SampleRate = ((XElement)track).Element("SampleRate").ToInt(0),
                Size = ((XElement)track).Element("Size").ToInt64(0),
                //Get the track time in total seconds
                TotalTime = ((XElement)track).Element("TotalTime").ToInt64(0) / 1000,
                TrackNumber = ((XElement)track).Element("TrackNumber").ToInt(0)
            })).ToList();
        }
開發者ID:ButchersBoy,項目名稱:iExporter,代碼行數:32,代碼來源:iTunesLibraryService.cs

示例9: HandleChildCollections

        private void HandleChildCollections(XElement document, object parentObject)
        {
            IEnumerable<XNode> xNodes = document.Nodes();
            foreach (XElement element in xNodes)
            {
                if (element.Attribute("ObjectType") != null)
                {
                    if (element.Attribute("ObjectType").Value == "Collection")
                    {
                        string assemblyQualifiedClassNameCollection = element.Attribute("AssemblyQualifiedClassName").Value;
                        Type collectionType = Type.GetType(assemblyQualifiedClassNameCollection);
                        System.Collections.IList childObjectCollection = (System.Collections.IList)Activator.CreateInstance(collectionType);

                        IEnumerable<XNode> childNodes = element.Nodes();
                        foreach (XElement childElement in childNodes)
                        {
                            string assemblyQualifiedClassNameChild = childElement.Attribute("AssemblyQualifiedClassName").Value;
                            Type childType = Type.GetType(assemblyQualifiedClassNameChild);
                            object childObject = Activator.CreateInstance(childType);
                            YellowstonePathology.Business.Persistence.XmlPropertyWriter rootXmlPropertyWriter = new Persistence.XmlPropertyWriter(childElement, childObject);
                            rootXmlPropertyWriter.Write();
                            childObjectCollection.Add(childObject);
                        }

                        PropertyInfo collectionPropertyInfo = parentObject.GetType().GetProperty(element.Name.ToString());
                        collectionPropertyInfo.SetValue(parentObject, childObjectCollection, null);
                    }
                }
            }
        }
開發者ID:ericramses,項目名稱:YPILIS,代碼行數:30,代碼來源:ObjectXMLBuilder.cs

示例10: RemoveAllNamespaces

 /// <summary>
 /// Removes all namespaces from a XDocument
 /// </summary>
 /// <param name="e"></param>
 /// <returns></returns>
 /// <remarks>Borrowed from http://stackoverflow.com/a/7238007/41596</remarks>
 public static XElement RemoveAllNamespaces(XElement e)
 {
     return new XElement(e.Name.LocalName,
                         (from n in e.Nodes()
                          select ((n is XElement) ? RemoveAllNamespaces(n as XElement) : n)),
                         (e.HasAttributes) ? (from a in e.Attributes() select a) : null);
 }
開發者ID:alexandernyquist,項目名稱:WebmasterToolsApi,代碼行數:13,代碼來源:XDocumentExtensions.cs

示例11: HandleXmlElement

        /// <inheritdoc/>
        protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, DocumentationCommentTriviaSyntax documentation, XmlNodeSyntax syntax, XElement completeDocumentation, Location[] diagnosticLocations)
        {
            if (syntax == null)
            {
                return;
            }

            if (completeDocumentation != null)
            {
                XElement summaryNode = completeDocumentation.Nodes().OfType<XElement>().FirstOrDefault(element => element.Name == XmlCommentHelper.SummaryXmlTag);
                if (summaryNode == null)
                {
                    // Handled by SA1604
                    return;
                }

                if (!XmlCommentHelper.IsConsideredEmpty(summaryNode))
                {
                    return;
                }
            }
            else
            {
                if (!XmlCommentHelper.IsConsideredEmpty(syntax))
                {
                    return;
                }
            }

            foreach (var location in diagnosticLocations)
            {
                context.ReportDiagnostic(Diagnostic.Create(Descriptor, location));
            }
        }
開發者ID:Romanx,項目名稱:StyleCopAnalyzers,代碼行數:35,代碼來源:SA1606ElementDocumentationMustHaveSummaryText.cs

示例12: MarkupHtmlElement

        /// <summary>
        /// Parse the HTML node at the given element.
        /// </summary>
        public MarkupHtmlElement(XElement element)
        {
            XAttribute idAttribute = element.Attribute("id");
            if (idAttribute != null && IsPublicId(idAttribute.Value))
            {
                Id = idAttribute.Value;
            }

            MarkupNode childrenNode = MarkupNode.Parse(element.Nodes());
            if (childrenNode == null
                || (childrenNode is MarkupHtmlElement
                    && ((MarkupHtmlElement)childrenNode).Id == null
                    && ((MarkupHtmlElement)childrenNode).ChildNodes == null))
            {
                // This node and everything it contains is plain HTML; use it as is.
                Html = element.ToString(SaveOptions.DisableFormatting);
            }
            else
            {
                // UNDONE: Optimization: Any children which are just HTML can be merged into this node.

                // Extract only the top-level tag information. To do this, create a
                // new element that has only the name and attributes.
                XElement topElement = new XElement(element.Name,
                    element.Attributes()
                );
                Html = topElement.ToString(SaveOptions.DisableFormatting);

                // Add in the children nodes.
                ChildNodes =
                    childrenNode is MarkupElementCollection
                        ? (MarkupElementCollection)childrenNode
                        : new MarkupElementCollection(new MarkupElement[] { (MarkupElement)childrenNode });
            }
        }
開發者ID:thomasvandoren,項目名稱:quickui,代碼行數:38,代碼來源:MarkupHtmlElement.cs

示例13: parseEntry

 static void parseEntry(XElement en, StreamWriter wr) {
   foreach (var nd in en.Nodes()) {
     if (nd is XElement) wr.Write(string.Format("<{0}>", LowUtils.crlfSpaces(((XElement)nd).Value)));
     else if (nd is XText) wr.Write(LowUtils.crlfSpaces(((XText)nd).Value));
     else throw new Exception();
   }
 }
開發者ID:PavelPZ,項目名稱:NetNew,代碼行數:7,代碼來源:DictWiki.cs

示例14: _ProcessConditional

 /// <summary>
 ///  Common logic for if/ifdef/ifndef/else constructs
 /// </summary>
 /// <param name="conditionalElement"></param>
 /// <param name="condition"></param>
 /// <returns></returns>
 protected IEnumerable< XNode > _ProcessConditional(XElement conditionalElement,
                                                    bool condition)
 {
     return condition
                ? _ProcessNodes( conditionalElement.Nodes() )
                : _ProcessNextElse( conditionalElement );
 }
開發者ID:BiYiTuan,項目名稱:CruiseControl.NET,代碼行數:13,代碼來源:ConditionalProcessor.cs

示例15: Collection

 public void Collection()
 {
     XElement element = new XElement("Foo",
         new XElement("Bar",
             new XAttribute("id", "bar"),
             "Control content"),
         new XElement("p", "paragraph")
     );
     MarkupNode node = MarkupNode.Parse(element.Nodes());
     Assert.IsInstanceOf<MarkupElementCollection>(node);
     MarkupElementCollection collection = (MarkupElementCollection)node;
     Assert.IsNotNull(collection);
     Assert.AreEqual(2, collection.Count());
     List<MarkupElement> items = new List<MarkupElement>(collection);
     Assert.IsInstanceOf<MarkupControlInstance>(items[0]);
     Assert.IsInstanceOf<MarkupHtmlElement>(items[1]);
     Assert.AreEqual(
         "[\n" +
         "    {\n" +
         "        control: \"Bar\",\n" +
         "        id: \"bar\",\n" +
         "        content: \"Control content\"\n" +
         "    },\n" +
         "    \"<p>paragraph</p>\"\n" +
         "]",
         node.JavaScript());
 }
開發者ID:JanMiksovsky,項目名稱:quickui-markup,代碼行數:27,代碼來源:MarkupElementCollectionTests.cs


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