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


C# XContainer.Nodes方法代碼示例

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


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

示例1: XContainer

 /// <summary>
 /// Clone ctor
 /// </summary>
 internal XContainer(XContainer source)
 {
     content = source.content as string;
     if ((content == null) && (source.content is XNode))
     {
         foreach (var node in source.Nodes())
         {
             Add(node.Clone(), false);
         }
     }
 }
開發者ID:nguyenkien,項目名稱:api,代碼行數:14,代碼來源:XContainer.cs

示例2: ReplaceWithExpValues

 private IEnumerable<ExpectedValue> ReplaceWithExpValues(XContainer elem, XNode toReplace, IEnumerable<object> replacement)
 {
     foreach (XNode n in elem.Nodes())
     {
         if (n != toReplace)
         {
             yield return new ExpectedValue(true, n);
         }
         else
         {
             foreach (object o in replacement)
             {
                 yield return new ExpectedValue(o is XNode && (o as XNode).Parent == null && (o as XNode).Document == null, o);
             }
         }
     }
 }
開發者ID:ChuangYang,項目名稱:corefx,代碼行數:17,代碼來源:XNodeReplace.cs

示例3: CalculateExpectedContent

        private IEnumerable<ExpectedValue> CalculateExpectedContent(XContainer orig, IEnumerable<object> newNodes, string stringOnlyContent)
        {
            if (stringOnlyContent == null)
            {
                foreach (object o in orig.Nodes())
                {
                    yield return new ExpectedValue(true, o);
                }
            }
            else
            {
                yield return new ExpectedValue(false, new XText(stringOnlyContent));
            }

            foreach (object n in newNodes.Flatten())
            {
                if (n is XAttribute)
                {
                    continue;
                }
                yield return new ExpectedValue((n is XNode) && (n as XNode).Parent == null && (n as XNode).Document == null, n);
            }
        }
開發者ID:Rayislandstyle,項目名稱:corefx,代碼行數:23,代碼來源:XContainerAddIntoElement.cs

示例4: GetInnerText

		string GetInnerText (XContainer node)
		{
			StringBuilder sb = null;
			foreach (XNode n in node.Nodes ())
				GetInnerText (n, ref sb);
			return sb != null ? sb.ToString () : String.Empty;
		}
開發者ID:calumjiao,項目名稱:Mono-Class-Libraries,代碼行數:7,代碼來源:XNodeNavigator.cs

示例5: TextValue

 private string TextValue(XContainer elem)
 {
     return elem.Nodes().OfType<XText>().Aggregate("", (s, text) => s + text);
 }
開發者ID:provegard,項目名稱:testness,代碼行數:4,代碼來源:XUnitReporterTest.cs

示例6: DoRemoveTest

        private void DoRemoveTest(XContainer elem, int position)
        {
            List<ExpectedValue> expectedData = elem.Nodes().Take(position).Concat(elem.Nodes().Skip(position + 1)).Select(n => new ExpectedValue(!(n is XText), n)).ProcessNodes().ToList();

            XNode toRemove = elem.Nodes().ElementAt(position);
            toRemove.Remove();

            TestLog.Compare(toRemove.Parent == null, "Parent of Removed");
            TestLog.Compare(toRemove.Document == null, "Document of Removed");
            TestLog.Compare(toRemove.NextNode == null, "NextNode");
            TestLog.Compare(toRemove.PreviousNode == null, "PreviousNode");
            if (toRemove is XContainer)
            {
                foreach (XNode child in (toRemove as XContainer).Nodes())
                {
                    TestLog.Compare(child.Document == null, "Document of child of Removed");
                    TestLog.Compare(child.Parent == toRemove, "Parent of child of Removed should be set");
                }
            }
            // try Remove Removed node
            try
            {
                toRemove.Remove();
                TestLog.Compare(false, "Exception expected [" + toRemove.NodeType + "] " + toRemove);
            }
            catch (InvalidOperationException)
            {
            }

            TestLog.Compare(expectedData.EqualAll(elem.Nodes(), XNode.EqualityComparer), "The rest of the tree - Nodes()");
        }
開發者ID:noahfalk,項目名稱:corefx,代碼行數:31,代碼來源:XNodeRemove.cs

示例7: ParseNodes

        private IEnumerable<TokenBase> ParseNodes(XContainer container, Stack<TextVisualProperties> propertiesStack, TokenIndex top, int bookLevel, int parentID = -1)
        {
            foreach (XNode node in container.Nodes())
            {
                var text = node as XText;
                if ((text != null) && !string.IsNullOrEmpty(text.Value))
                {
                    foreach (TokenBase token in ParseText(text.Value, top))
                    {
                        yield return token;
                    }
                }
                var element = node as XElement;
                if(element == null)
                    continue;

                TextVisualProperties properties = propertiesStack.Peek().Clone().Update(element, _styleSheet);
                
                string localName = element.Name.LocalName;
                int level = bookLevel;

                if (localName == "a")
                {
                    ProcessLinks(properties, element);
                }
                ProcessAnchors(top, element);

                if (localName == "section")
                {
                    yield return new NewPageToken(top.Index++);
                    level++;
                }

                if (localName == "title")
                {
                    ProcessTitleData(top, element, level);
                }

                if (localName == "image")
                {
                    XAttribute hrefAttr = element.Attributes().FirstOrDefault(t => (t.Name.LocalName == "href"));
                    string href = ((hrefAttr != null) ? hrefAttr.Value : string.Empty).TrimStart('#');
                    var pictureToken = new PictureToken(top.Index++, href);
                    yield return pictureToken;
                }
                else
                {
                    var tagOpen = new TagOpenToken(top.Index++, element, properties, parentID);
                    yield return tagOpen;

                    propertiesStack.Push(properties);
                    foreach (TokenBase token in ParseNodes(element, propertiesStack, top, level, tagOpen.ID))
                    {
                        yield return token;
                    }
                    propertiesStack.Pop();

                    yield return new TagCloseToken(top.Index++, parentID);
                }
                
            }
        }
開發者ID:bdvsoft,項目名稱:reader_wp8_OPDS,代碼行數:62,代碼來源:Fb2TokenParser.cs

示例8: ReparentChildren

		private static void ReparentChildren(
				XContainer originalParent, XContainer newParent)
		{
			// re-parent all descendants from originalParent into newParent
			List<XNode> childNodes = new List<XNode>();
			foreach (XNode d in originalParent.Nodes())
			{
				childNodes.Add(d);
			}
			foreach (XNode d in childNodes)
			{
				d.Remove();
				newParent.Add(d);
			}
		}
開發者ID:nHydrate,項目名稱:nHydrate,代碼行數:15,代碼來源:EdmGen2.cs

示例9: SelectDirectDescendents

		private static IEnumerable<XElement> SelectDirectDescendents(
			 XContainer root, XName name)
		{
			List<XElement> selected = new List<XElement>();
			foreach (XNode node in root.Nodes())
			{
				if (node.NodeType == XmlNodeType.Element)
				{
					XElement e = node as XElement;
					if (e != null)
					{
						if (e.Name.Equals(name))
						{
							selected.Add(e);
						}
					}
				}
			}
			return selected;
		}
開發者ID:nHydrate,項目名稱:nHydrate,代碼行數:20,代碼來源:EdmGen2.cs

示例10: TransferChildren

		private static void TransferChildren(
			 XContainer originalParent, XContainer newParent)
		{
			// now move all descendants into this node
			List<XNode> childNodes = new List<XNode>();
			foreach (XNode d in originalParent.Nodes())
			{
				childNodes.Add(d);
			}
			foreach (XNode d in childNodes)
			{
				d.Remove();
				newParent.Add(d);
			}
		}
開發者ID:nHydrate,項目名稱:nHydrate,代碼行數:15,代碼來源:EdmGen2.cs

示例11: AddLeadingIndentation

 private static void AddLeadingIndentation(XContainer container, string containerIndent, string oneIndentLevel)
 {
     var containerIsSelfClosed = !container.Nodes().Any();
     var lastChildText = container.LastNode as XText;
     if (containerIsSelfClosed || lastChildText == null)
     {
         container.Add(new XText(containerIndent + oneIndentLevel));
     }
     else
     {
         lastChildText.Value += oneIndentLevel;
     }
 }
開發者ID:eerhardt,項目名稱:NuGet3,代碼行數:13,代碼來源:XmlUtility.cs


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