AppendNode
Append new child XmlElement to base XmlElement.
Source
public static void AppendNode<T>(this XmlElement root, string name, T value)
{
XmlDocument doc = root.OwnerDocument;
if (doc != null)
{
XmlElement code = doc.CreateElement(name);
XmlText codeText = doc.CreateTextNode(value.ToString());
root.AppendChild(code);
code.AppendChild(codeText);
}
}
Example
XmlDocument doc = new XmlDocument();
XmlElement root = doc.CreateElement("Root");
doc.AppendChild(root);
root.AppendNode("Child 1 Name", "Child 1 Value");
root.AppendNode("Child 2 Name", 123);
Author: Dumitru Condrea
Submitted on: 25 nov. 2010
Language: C#
Type: System.Xml.XmlElement
Views: 4375