Set XML Element Text - CSharp System.Xml

CSharp examples for System.Xml:XML Element

Description

Set XML Element Text

Demo Code


using System.Xml;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;//from  w  w  w .j a v a 2  s  .c  o  m

public class Main{
        public static void SetElementText(this XmlElement parent, string elemName, string value)
        {
            XmlElement element = parent.CreateChildElement(elemName);
            XmlText text = parent.OwnerDocument.CreateTextNode(value);
            element.AppendChild(text);
        }
        public static XmlElement CreateChildElement(this XmlElement parent, string elemName)
        {
            XmlElement element = parent.OwnerDocument.CreateElement(elemName);
            parent.AppendChild(element);
            return element;
        }
}

Related Tutorials