View Single Post
 
Old December 14th, 2006, 04:50 AM
joefawcett's Avatar
joefawcett joefawcett is offline
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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)