using System.Linq; using System.Xml; namespace Abp.Xml.Extensions { /// /// Extension methods for class. /// public static class XmlNodeExtensions { /// /// Gets an attribute's value from an Xml node. /// /// The Xml node /// Attribute name /// Value of the attribute public static string GetAttributeValueOrNull(this XmlNode node, string attributeName) { if (node.Attributes == null || node.Attributes.Count <= 0) { throw new AbpException(node.Name + " node has not " + attributeName + " attribute"); } return node.Attributes .Cast() .Where(attr => attr.Name == attributeName) .Select(attr => attr.Value) .FirstOrDefault(); } } }