Casting XML element to string - CSharp System.Xml

CSharp examples for System.Xml:XML Element

Description

Casting XML element to string

Demo Code


using System.Xml.Linq;
using System;//w w  w. ja va 2 s .c om

public class Main{
        /// <summary>
        /// Casting element to string
        /// </summary>
        /// <param name="element"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static String CastAttributeToString(this XElement element, String key)
        {
            if (element.Attribute(key) == null) { return ""; }
            return element.Attribute(key).Value;
        }
}

Related Tutorials