XmlReader reader = XmlReader.Create("example.xml"); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element && reader.Name == "title") { reader.MoveToContent(); Console.WriteLine("Title: " + reader.Value); } }
XmlDocument doc = new XmlDocument(); doc.LoadXml("In this example, we load an XML document into an XmlDocument object and select a specific element using XPath notation. We then use the MoveToContent method to move to the text content of that element and print it out. Package library: System.Xml.XmlDocument"); XmlNode element = doc.SelectSingleNode("/root/element"); element.MoveToContent(); Console.WriteLine(element.Value); some text