Get an optional attribute value from an XmlNode. - CSharp System.Xml

CSharp examples for System.Xml:XML Attribute

Description

Get an optional attribute value from an XmlNode.

Demo Code


using System.Xml;
using System.Collections.Generic;
using System;/*from   w  ww .ja v  a 2  s  .  co  m*/

public class Main{
        /// <summary>
      /// Get an optional attribute value from an XmlNode.
      /// </summary>
      /// <param name="node">The XmlNode to look in.</param>
      /// <param name="attrName">The attribute to find.</param>
      /// <returns>The value of the attribute, or null, if not found.</returns>
      public static string GetAttributeValue(XmlNode node, string attrName)
      {
         return GetOptionalAttributeValue(node, attrName);
      }
        /// <summary>
      /// Deprecated: use GetOptionalAttributeValue instead.
      /// </summary>
      /// <param name="node"></param>
      /// <param name="attrName"></param>
      /// <param name="defaultValue"></param>
      /// <returns></returns>
      public static string GetAttributeValue(XmlNode node, string attrName, string defaultValue)
      {
         return GetOptionalAttributeValue(node, attrName, defaultValue);
      }
}

Related Tutorials