System.Xml.Linq.XmlHelper.GetAttributesValue C# (CSharp) Method

GetAttributesValue() public method

获取所有被xPath匹配到的元素的属性,如果属性不存在,返回""
public GetAttributesValue ( string xPath, string attributeName ) : List
xPath string xPath表达式
attributeName string 要获取的属性
return List
        public List<string> GetAttributesValue(string xPath, string attributeName)
        {
            var result = new List<string>();
            if (string.IsNullOrEmpty(attributeName)) return result;
            var elements = _doc.XPathSelectElements(xPath);
            result.AddRange(from element in elements where element.HasAttributes select element.Attribute(attributeName) into attr where attr != null select attr.Value);
            return result;
        }