本文整理匯總了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);
}
}
}
示例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);
}
}
}
}
示例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);
}
}
示例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;
}
示例5: TextValue
private string TextValue(XContainer elem)
{
return elem.Nodes().OfType<XText>().Aggregate("", (s, text) => s + text);
}
示例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()");
}
示例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);
}
}
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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;
}
}