using System.Xml; XmlTextReader reader = new XmlTextReader("file.xml"); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element && reader.Name == "someElement") { string elementString = reader.ReadElementString(); Console.WriteLine(elementString); } } reader.Close();
using System.Xml; string xmlString = "In both examples, the code reads an XML file or string and searches for an element with a specific name. Once the element is found, the ReadElementString method is called to extract the text content of the element. This value is then printed to the console. In summary, System ReadElementString is a useful method in the C# language that allows developers to extract the string value of an XML element. It is part of the System.Xml package library.some text "; XmlReader reader = XmlReader.Create(new StringReader(xmlString)); if (reader.ReadToFollowing("someElement")) { string elementString = reader.ReadElementString(); Console.WriteLine(elementString); } reader.Close();