using System.Xml; XmlReader reader = XmlReader.Create("example.xml"); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element && reader.Name == "item") { string innerXml = reader.ReadInnerXml(); Console.WriteLine(innerXml); } }
using System.Xml; XmlReader reader = XmlReader.Create("example.xml"); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element && reader.Name == "book") { string title = reader.GetAttribute("title"); string author = reader.GetAttribute("author"); string innerXml = reader.ReadInnerXml(); Console.WriteLine($"{title} by {author}: {innerXml}"); } }In this code, ReadInnerXml is called after reading an XML "book" element node that has both "title" and "author" attributes. The title, author, and inner XML content of the "book" element node are printed to the console. Package library: The System.Xml namespace is part of the .NET Framework Class Library.