// Load the XML document XmlDocument doc = new XmlDocument(); doc.Load("movies.xml"); // Select the movie node with the title "The Shawshank Redemption" XmlNode movieNode = doc.SelectSingleNode("//movie[title='The Shawshank Redemption']"); // Get the title of the movie string title = movieNode.SelectSingleNode("title").InnerText; Console.WriteLine(title); // Output: The Shawshank Redemption
// Load the XML document XmlDocument doc = new XmlDocument(); doc.Load("books.xml"); // Select all the book nodes with the author "Stephen King" XmlNodeList bookNodes = doc.SelectNodes("//book[author='Stephen King']"); // Loop through the book nodes and print the titles foreach (XmlNode bookNode in bookNodes) { string title = bookNode.SelectSingleNode("title").InnerText; Console.WriteLine(title); }These examples use the System.Xml package library, which is a part of the .NET Framework.