public ReadElementContentAsString ( ) : string | ||
return | string |
XmlReader reader = XmlReader.Create("example.xml"); reader.MoveToContent(); // Read the value of the "name" element string name = reader.ReadElementContentAsString("name", "");
XmlReader reader = XmlReader.Create("example.xml"); reader.MoveToContent(); // Read the values of all "item" elements and store them in a list ListThis example creates an XmlReader object and moves to the content of the XML document. It then reads all the "item" elements and stores their values in a list. Package library: System.Xml.items = new List (); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element && reader.Name == "item") { string item = reader.ReadElementContentAsString(); items.Add(item); } }