Get XML Node Value via XPath - CSharp System.Xml

CSharp examples for System.Xml:XML Node

Description

Get XML Node Value via XPath

Demo Code


using System.Xml;
using System;//  ww  w .  j  av a2 s  .com

public class Main{
        public static string GetNodeValue(XmlNode xmlNode, string searchPath)
        {
            try
            {
                if (xmlNode != null)
                {
                    var selectSingleNode = xmlNode.SelectSingleNode(searchPath);
                    if (selectSingleNode != null)
                        return selectSingleNode.InnerText;
                }
                return string.Empty;
            }
            catch (Exception)
            {
                return string.Empty;
            }
        }
}

Related Tutorials