Read Single Node from XML String - CSharp System.Xml

CSharp examples for System.Xml:XML String

Description

Read Single Node from XML String

Demo Code


using System.Xml;
using System.Collections.Generic;

public class Main{
        public static string ReadSingleNode(this string xml, string nodeXPath)
        {//from w  w  w  .  ja v a 2  s  .co m
            XmlDocument xmlDocument = new XmlDocument();
            xmlDocument.LoadXml(xml);

            XmlNode node = xmlDocument.SelectSingleNode(nodeXPath);
            return (node == null) ? string.Empty : node.InnerText;
        }
}

Related Tutorials