XmlExtensions.cs 959 B

12345678910111213141516171819202122232425262728293031323334
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Xml;
  7. namespace FWindSoft.SystemExtensions
  8. {
  9. /// <summary>
  10. /// xml属性扩展
  11. /// </summary>
  12. public static class XmlAttributeExtensions
  13. {
  14. /// <summary>
  15. /// 在已知属性集合中获取给点键值的属性值,如果不存在返回""
  16. /// </summary>
  17. /// <param name="attributes"></param>
  18. /// <param name="name"></param>
  19. /// <returns></returns>
  20. public static string GetAttributeValue(this XmlAttributeCollection attributes, string name)
  21. {
  22. if (attributes == null)
  23. return "";
  24. if (string.IsNullOrWhiteSpace(name))
  25. return "";
  26. var attribute = attributes[name];
  27. if (attribute == null)
  28. return "";
  29. return attribute.Value;
  30. }
  31. }
  32. }