There are a few different ways, the easiest is probably to load the string into an XPathDocument via a StringReader, if the XML is a file you can use a StreamReader instead. Then use the XPathNavigator to select the desired value.
The code for a console application is shown here:
Code:
using System;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.XPath;
namespace XmlFromString
{
class Program
{
static void Main(string[] args)
{
string xml = "<order/>"; //Full order document to go here
XPathDocument doc = new XPathDocument(new StringReader(xml));
string xpath = "/*/payment/chargetotal";
XPathNavigator nav = doc.CreateNavigator();
XPathNavigator node = nav.SelectSingleNode(xpath);
Console.WriteLine("{0}: {1}", node.Name, node.InnerXml);
Console.ReadLine();
}
}
}
--
Joe (
Microsoft MVP - XML)