| 12345678910111213141516171819202122232425262728293031 |
- using System.Linq;
- using System.Xml;
- namespace Abp.Xml.Extensions
- {
- /// <summary>
- /// Extension methods for <see cref="XmlNode"/> class.
- /// </summary>
- public static class XmlNodeExtensions
- {
- /// <summary>
- /// Gets an attribute's value from an Xml node.
- /// </summary>
- /// <param name="node">The Xml node</param>
- /// <param name="attributeName">Attribute name</param>
- /// <returns>Value of the attribute</returns>
- 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<XmlAttribute>()
- .Where(attr => attr.Name == attributeName)
- .Select(attr => attr.Value)
- .FirstOrDefault();
- }
- }
- }
|