CSharp examples for System.Xml:XML Element
Adds the a new element as a child of an existing node and returns it. A CDataSection is added to the new element using the data provided.
// Permission is hereby granted, free of charge, to any person obtaining using System.Xml; using System.Globalization; using System.Collections.Generic; using System;/*www . j av a 2s . c o m*/ public class Main{ /// <summary> /// Adds the a new element as a child of an existing node and returns it. /// A CDataSection is added to the new element using the data provided. /// </summary> /// <param name="node">The node to which the element should be added.</param> /// <param name="name">The element name.</param> /// <param name="data">The data for the CDataSection.</param> /// <returns></returns> public static XmlNode AddElementWithCDataSection(this XmlNode node, string name, string data) { XmlNode childNode = node.AddElement(name); childNode.AppendChild(node.OwnerDocument.CreateCDataSection(data)); return childNode; } /// <summary> /// Adds a new element as a child of an existing XmlNode and returns it. /// </summary> /// <param name="node">The node to which the element should be added.</param> /// <param name="name">The element name.</param> /// <returns>The newly created child element</returns> public static XmlNode AddElement(this XmlNode node, string name) { XmlNode childNode = node.OwnerDocument.CreateElement(name); node.AppendChild(childNode); return childNode; } }