XmlDocument xmlDoc = new XmlDocument(); if (!File.Exists(xmlFileName)) { return string.Empty; } xmlDoc.Load(xmlFileName); XmlNodeList nodes = xmlDoc.SelectNodes(keyPath); foreach (XmlNode node in nodes) { foreach (XmlNode childNode in node.ChildNodes) { if (childNode.Name == keyName.ToUpper()) { string dataValue = childNode.InnerText; return dataValue; } } }