Well, there is a reason why XML parsing has improved since 2.0, but if you just want a sample that parses that fragment without using XmlReader
, this should work. I'm sure there are other ways of doing this:
XmlDocument doc = new XmlDocument();
doc.LoadXml(@"<nodes><node id=""123""><text>text goes here</text></node><node id=""321""><text>more text goes here</text></node></nodes>");
foreach (XmlNode nodes in doc.GetElementsByTagName("nodes"))
{
foreach (XmlNode node in nodes.ChildNodes)
{
XmlNodeList list = node.SelectNodes("text");
if (list.Count > 0)
{
Console.Write("{0}='{1}'\n", node.Attributes["id"].Value, list[0].InnerText);
}
}
}
Console.WriteLine("Done.");
Console.ReadKey();