本文整理汇总了C#中System.Xml.XmlElement.RemoveAll方法的典型用法代码示例。如果您正苦于以下问题:C# XmlElement.RemoveAll方法的具体用法?C# XmlElement.RemoveAll怎么用?C# XmlElement.RemoveAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlElement
的用法示例。
在下文中一共展示了XmlElement.RemoveAll方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaveNode
private void SaveNode(XmlDocument xmlDoc, XmlElement nodeElement, SaveContext context)
{
if (context == SaveContext.Copy || context == SaveContext.Undo)
{
//Dump all the information into memory
nodeElement.SetAttribute("inputCount", InputCount.ToString());
nodeElement.SetAttribute("outputCount", OutputCount.ToString());
nodeElement.SetAttribute("legacyNodeName", LegacyNodeName);
nodeElement.SetAttribute("legacyAssembly", LegacyAssembly);
nodeElement.SetAttribute("nodeNature", NodeNature.ToString());
if (OriginalNodeContent != null)
{
XmlElement originalNode = xmlDoc.CreateElement("OriginalNodeContent");
XmlElement nodeContent = nodeElement.OwnerDocument.CreateElement(OriginalNodeContent.Name);
foreach (XmlAttribute attribute in OriginalNodeContent.Attributes)
nodeContent.SetAttribute(attribute.Name, attribute.Value);
for (int i = 0; i < OriginalNodeContent.ChildNodes.Count; i++)
{
XmlNode child =
nodeContent.OwnerDocument.ImportNode(OriginalNodeContent.ChildNodes[i], true);
nodeContent.AppendChild(child.CloneNode(true));
}
originalNode.AppendChild(nodeContent);
nodeElement.AppendChild(originalNode);
}
}
if (context == SaveContext.File)
{
//When save files, only save the original node's content,
//instead of saving the dummy node.
if (OriginalNodeContent != null)
{
nodeElement.RemoveAll();
foreach (XmlAttribute attribute in OriginalNodeContent.Attributes)
nodeElement.SetAttribute(attribute.Name, attribute.Value);
//overwrite the guid/x/y value of the original node.
nodeElement.SetAttribute("guid", nodeElement.GetAttribute("guid"));
nodeElement.SetAttribute("x", nodeElement.GetAttribute("x"));
nodeElement.SetAttribute("y", nodeElement.GetAttribute("y"));
for (int i = 0; i < OriginalNodeContent.ChildNodes.Count; i++)
{
XmlNode child = nodeElement.OwnerDocument.ImportNode(OriginalNodeContent.ChildNodes[i], true);
nodeElement.AppendChild(child.CloneNode(true));
}
}
else
{
nodeElement.SetAttribute("inputCount", InputCount.ToString());
nodeElement.SetAttribute("outputCount", OutputCount.ToString());
nodeElement.SetAttribute("legacyNodeName", LegacyNodeName);
nodeElement.SetAttribute("legacyAssembly", LegacyAssembly);
nodeElement.SetAttribute("nodeNature", NodeNature.ToString());
}
}
}
示例2: saveTestRemoveAllAffectOnEnumeration
// TODO: Take the word save off front of this method when XmlNode.RemoveAll() is fully implemented.
public void saveTestRemoveAllAffectOnEnumeration ()
{
document.LoadXml ("<foo><child1/><child2/><child3/></foo>");
element = document.DocumentElement;
enumerator = element.GetEnumerator();
Assert.AreEqual (element.ChildNodes.Count, 3, "Expected 3 children.");
Assert.AreEqual (enumerator.MoveNext(), true, "MoveNext should have succeeded.");
element.RemoveAll();
Assert.AreEqual (enumerator.MoveNext(), false, "MoveNext should have failed.");
}
示例3: RemoveElement
public void RemoveElement(XmlElement ele)
{
ele.RemoveAll();
}