本文整理汇总了C#中System.Xml.XmlDocument.CloneNode方法的典型用法代码示例。如果您正苦于以下问题:C# XmlDocument.CloneNode方法的具体用法?C# XmlDocument.CloneNode怎么用?C# XmlDocument.CloneNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlDocument
的用法示例。
在下文中一共展示了XmlDocument.CloneNode方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CloneComplexDocumentTrue
public static void CloneComplexDocumentTrue()
{
var xmlDocument = new XmlDocument();
xmlDocument.LoadXml(ComplexDocument);
var cloned = xmlDocument.CloneNode(true);
Assert.NotSame(xmlDocument.ChildNodes, cloned.ChildNodes);
Assert.Equal(xmlDocument.NodeType, cloned.NodeType);
Assert.Equal(xmlDocument.ChildNodes.Count, cloned.ChildNodes.Count);
Assert.Equal(xmlDocument.LastChild.Value, cloned.LastChild.Value);
// Test XmlNode.LastChild
{
for (var i = 0; i < xmlDocument.ChildNodes.Count; i++)
{
if (xmlDocument.ChildNodes[i].LastChild == null)
{
Assert.Equal(xmlDocument.ChildNodes[i].LastChild, cloned.ChildNodes[i].LastChild);
}
else
{
Assert.Equal(xmlDocument.ChildNodes[i].LastChild.Value, cloned.ChildNodes[i].LastChild.Value);
}
}
}
// Test XmlNode.NextSibling
{
var count = cloned.ChildNodes.Count;
var previousNode = cloned.ChildNodes[0];
for (var idx = 1; idx < count; idx++)
{
var currentNode = cloned.ChildNodes[idx];
Assert.Equal(currentNode, previousNode.NextSibling);
previousNode = currentNode;
}
Assert.Null(previousNode.NextSibling);
}
// Test XmlNode.PreviousSibling
{
var count = cloned.ChildNodes.Count;
var nextNode = cloned.ChildNodes[count - 1];
for (var idx = count - 2; idx >= 0; idx--)
{
var currentNode = cloned.ChildNodes[idx];
Assert.Equal(currentNode, nextNode.PreviousSibling);
nextNode = currentNode;
}
Assert.Null(nextNode.PreviousSibling);
}
// Test XmlNode.ParentNode
CheckChildren(cloned);
}
示例2: Sign
public XmlDocument Sign(
XmlDocument message,
String nonce,
DateTime expiresAt
)
{
if (message.DocumentElement == null)
throw new ArgumentException("No root node in xdoc.");
var copy = (XmlDocument)message.CloneNode(true);
SignMessage(
copy.DocumentElement,
Convert.FromBase64String(nonce),
expiresAt,
new SharedSecret().From(_password)
);
return copy;
}
示例3: CloneXmlDoc
/// <summary>
/// Make a copy of a XmlDocument
/// </summary>
/// <param name="xmlDoc"></param>
/// <returns></returns>
private static XmlDocument CloneXmlDoc(XmlDocument xmlDoc)
{
if (xmlDoc == null) return null;
Log.Add(LogTypes.Debug, -1, "Cloning...");
// Save copy of content
var xmlCopy = (XmlDocument)xmlDoc.CloneNode(true);
Log.Add(LogTypes.Debug, -1, "Cloning ended...");
return xmlCopy;
}
示例4: CloneComplexDocumentTrueAndManipulate
public static void CloneComplexDocumentTrueAndManipulate()
{
var xmlDocument = new XmlDocument();
xmlDocument.LoadXml("<a>test</a>");
var cloned = xmlDocument.CloneNode(true);
cloned.FirstChild.FirstChild.Value = "replaced";
Assert.Equal("test", xmlDocument.FirstChild.FirstChild.Value);
Assert.Equal("replaced", cloned.FirstChild.FirstChild.Value);
}
示例5: CloneXmlDoc
/// <summary>
/// Make a copy of a XmlDocument
/// </summary>
/// <param name="xmlDoc"></param>
/// <returns></returns>
private static XmlDocument CloneXmlDoc(XmlDocument xmlDoc)
{
if (xmlDoc == null) return null;
// Save copy of content
var xmlCopy = (XmlDocument)xmlDoc.CloneNode(true);
return xmlCopy;
}
示例6: CloneNode
public void CloneNode ()
{
XmlDocument doc = new XmlDocument ();
doc.LoadXml ("<foo><bar /><baz hoge='fuga'>TEST Text</baz></foo>");
XmlDocument doc2 = (XmlDocument)doc.CloneNode (false);
AssertEquals ("ShallowCopy", 0, doc2.ChildNodes.Count);
doc2 = (XmlDocument)doc.CloneNode (true);
AssertEquals ("DeepCopy", "foo", doc2.DocumentElement.Name);
}
示例7: DeserializeElement
protected override void DeserializeElement (XmlReader reader, bool serializeCollectionKey)
{
original = new XmlDocument ().ReadNode (reader);
node = original.CloneNode (true);
}