CgwMonitorManage.Common.CommonFunction.GetAttribute C# (CSharp) Method

GetAttribute() public static method

读取节点信息
public static GetAttribute ( XmlElement xmlElement, string nodeName, string attributeName ) : string
xmlElement System.Xml.XmlElement
nodeName string
attributeName string
return string
        public static string GetAttribute(XmlElement xmlElement, string nodeName, string attributeName)
        {
            XmlNode node = xmlElement.SelectSingleNode(nodeName);
            if (node == null)
            {
                throw new Exception(string.Format("The node is not contain the attribute.Node:{0},attribute:{1}.", nodeName, attributeName));
            }

            XmlElement element = node as XmlElement;
            if (element == null)
            {
                throw new Exception(string.Format("The node is not contain the attribute.Node:{0},attribute:{1}.", nodeName, attributeName));
            }
            string attributeValue = element.GetAttribute(attributeName).Trim();
            if (string.IsNullOrEmpty(attributeValue))
            {
                throw new Exception(string.Format("The node is not contain the attribute.Node:{0},attribute:{1}.", nodeName, attributeName));
            }

            return attributeValue;
        }