public bool Attribute_Present_Or_not(string user_defined_attribute, string user_defined_xml_file, string user_defined_xpath) { bool chk_result = false; try { XmlDocument user_xml_document = new XmlDocument(); user_xml_document.Load(user_defined_xml_file); XmlNodeList user_nodeList = user_xml_document.SelectNodes(user_defined_xpath); XmlElement root = user_xml_document.DocumentElement; foreach (XmlNode user_node in user_nodeList) { try{ if (user_node.Attributes.GetNamedItem(user_defined_attribute)!=null) { chk_result = true; return chk_result; } } catch (Exception ) { chk_result = false; return chk_result; } } } catch (NullReferenceException) { chk_result = false; return chk_result; } catch (XPathException) { chk_result = false; return chk_result; } return chk_result; }