Creates and returns the XML element with the given name located in the given location string in the given XML element. - CSharp System.Xml

CSharp examples for System.Xml:XML Element

Description

Creates and returns the XML element with the given name located in the given location string in the given XML element.

Demo Code


using System.Linq;
using System.Text;
using System.Collections.Generic;
using System.Globalization;
using System.Xml.Linq;
using System;/*w  ww  .jav a  2  s.c  o m*/

public class Main{
        /// <summary>
        /// Creates and returns the XML element with the given name located in the 
        /// given location string in the given XML element.
        /// </summary>
        /// <param name="baseElement">The parent XML element.</param>
        /// <param name="location">The location string.</param>
        /// <param name="elemName">Name of the element to create.</param>
        /// <param name="elemValue">The element value to be assigned to the created element.</param>
        /// <returns>returns the XML element with the given name located in the 
        /// given location string in the given XML element.</returns>
        public static XElement CreateElement(XElement baseElement, string location, XName elemName, object elemValue)
        {
            XElement elem = CreateElement(baseElement, location, elemName);
            if (elem != null)
                elem.SetValue(elemValue);
            return elem;
        }
        /// <summary>
        /// Creates and returns the XML element with the given name located in the 
        /// given location string in the given XML element.
        /// </summary>
        /// <param name="baseElement">The parent XML element.</param>
        /// <param name="location">The location string.</param>
        /// <param name="elemName">Name of the element to create.</param>
        /// <returns>returns the XML element with the given name located in the 
        /// given location string in the given XML element</returns>
        public static XElement CreateElement(XElement baseElement, string location, XName elemName)
        {
            return CreateLocation(baseElement, StringUtils.CombineLocationAndElementName(location, elemName));
        }
}

Related Tutorials