Mega Code Archive

 
Categories / C# / XML
 

XmlReader ReadSubtree reads the current node, and all its descendants

using System; using System.Xml; public class Sample {      public static void Main()      {             XmlReaderSettings settings = new XmlReaderSettings();             settings.IgnoreWhitespace = true;             using (XmlReader reader = XmlReader.Create("books.xml", settings)) {                                // Position the reader on the second book node                   reader.ReadToFollowing("Book");                   reader.Skip();                                    // Create another reader that contains just the second book node.                   XmlReader inner = reader.ReadSubtree();                                    inner.ReadToDescendant("Title");                   Console.WriteLine(inner.Name);                                    inner.Close();              }      } }