public ReadElementContentAs ( |
||
returnType | ||
namespaceResolver | IXmlNamespaceResolver | |
return | object |
XmlReader reader = XmlReader.Create("example.xml"); reader.ReadToFollowing("price"); decimal price = reader.ReadElementContentAsDecimal();
XmlReader reader = XmlReader.Create("example.xml"); while (reader.Read()) { if (reader.IsStartElement("book") && reader["genre"] == "mystery") { string title = reader.ReadElementContentAsString("title", ""); int year = reader.ReadElementContentAsInt("year", ""); Console.WriteLine("Title: {0}, Year: {1}", title, year); } }This code reads an XML file and iterates through all of the "book" elements with a genre attribute of "mystery". It then reads the "title" and "year" elements within each "book" element and prints them to the console. These examples are part of the System.Xml.dll library, which is included in the .NET Framework.
public ReadElementContentAs ( |
||
returnType | ||
namespaceResolver | IXmlNamespaceResolver | |
return | object |