November 2001
Beginner to intermediate
816 pages
16h 3m
English
The System.Xml namespace has several classes for making reading of XML files easy. These classes encapsulate the code necessary to parse these files and obtain data related to specific tags. Listing 18.2 shows how to read and parse pertinent data from the file that was written by the method in Listing 18.1.
/// <summary> /// read XML data from a file /// </summary> void ReadXML() { XmlTextReader xr = new XmlTextReader(fileName); string nodeName; while (xr.Read()) { nodeName = xr.Name; if (nodeName == "Talk") { talk.Add(xr.ReadString()); } } xr = new XmlTextReader(fileName); XmlDocument xd = new XmlDocument(); xd.PreserveWhitespace = true; xd.Load(xr); Console.WriteLine(xd.InnerXml); xr.Close(); } ... |
Read now
Unlock full access