Skipping over Nodes

Many times when reading an XML stream, you find that you are searching for one particular node or parent node in the document that meets a certain criterion. The XmlTextReader does not provide any methods that will allow you to find one particular node quickly. Therefore, searching an XML stream with the XmlTextReader can be both complicated and processor intensive. These issues can be alleviated if you design your XML data carefully. Listing 10.19 illustrates how to build a method that will search for a given error message in an XML document with the Skip method.

Listing 10.19.
 C# public string FindErrorMessage(string filename, int catNumber, int errorNumber) { XmlTextReader reader = new XmlTextReader(filename); reader.WhitespaceHandling ...

Get Microsoft® .NET Compact Framework Kick Start now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.