using (XmlReader reader = XmlReader.Create("XMLFile1.xml")) { while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: if (reader.ReadToFollowing("title")) { output.AppendLine("Title: " + reader.ReadElementContentAsString()); output.AppendLine(); } if (reader.ReadToFollowing("first-name")) { output.AppendLine("First Name: " + reader.ReadElementContentAsString()); output.AppendLine(); } if (reader.ReadToFollowing("last-name")) { output.AppendLine("Last Name: " + reader.ReadElementContentAsString()); output.AppendLine(); } if (reader.ReadToFollowing("price")) { output.AppendLine("Price: " + reader.ReadElementContentAsString()); } break; } } textblockTitle.Text = output.ToString(); output.Remove(0, output.Length); }
<!-- This is a sample XML document --> <bookstore> <book genre="autobiography" publicationdate="1981-03-22" isbn="1-861003-11-0"> <title>The Autobiography of Benjamin Franklin</title> <author> <first-name>Benjamin</first-name> <last-name>Franklin</last-name> </author> <price>8.99</price> </book> </bookstore>
XmlDocument
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)