Mega Code Archive

 
Categories / C# / XML
 

Gets a string from an attribute or node

//Microsoft Public License (Ms-PL) //http://visualizer.codeplex.com/license using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml; namespace Redwerb.BizArk.Core.XmlExt {     /// <summary>     /// Provides extension methods for processing Xml.     /// </summary>     public static class XmlExt     {         /// <summary>         /// Gets a string from an attribute or node.         /// </summary>         /// <param name="node"></param>         /// <param name="name"></param>         /// <param name="dfltVal"></param>         /// <returns></returns>         public static string GetString(this XmlNode node, string name, string dfltVal)         {             var att = node.Attributes[name];             if (att != null) return att.Value;             var child = node.SelectSingleNode(name);             if (child != null) return child.InnerText;             return dfltVal;         }     } }