public GetAttributeValue ( string xPath, string attributeName ) : string | ||
xPath | string | xPath表达式 |
attributeName | string | 要获取的属性 |
return | string |
public string GetAttributeValue(string xPath, string attributeName)
{
var result = string.Empty;
if (string.IsNullOrEmpty(attributeName)) return result;
XElement element = _doc.XPathSelectElement(xPath);
if (element == null) return result;
if (!element.HasAttributes) return result;
XAttribute attr = element.Attribute(attributeName);
if (attr == null) return result;
result = attr.Value;
return result;
}