Returns whether or not XML element has an attribute set. - CSharp System.Xml

CSharp examples for System.Xml:XML Element

Description

Returns whether or not XML element has an attribute set.

Demo Code


using System.Xml.Linq;
using System.Globalization;
using System;//from   w ww.j  a  va  2s. c  om

public class Main{
        /// <summary>
      /// Returns whether or not an element has an attribute set.
      /// </summary>
      /// <param name="element">The XML element to search for the attribute on.</param>
      /// <param name="name">The name of the attribute to find.</param>
      /// <returns>true if the element has the attribute set.</returns>
      public static bool HasAttribute (XElement element, string name)
      {
         return ( element.Attribute(name) != null );
      }
}

Related Tutorials