Document-Based Parsing with DOM Under .NET

Although event-based parsing is fast and memory efficient, as you saw in the previous sections, it doesn't provide any context for where the current element is in the hierarchy of the document. This is due to the fact that parsing via a parser like XmlTextReader is effectively a one-shot operation: The parser only knows about the current element after each call is made to the XmlTextReader.Read() method and then promptly forgets about it.

For applications in which it is useful to have the parser remember more contextual information, using a parser that implements DOM is appropriate. DOM has the advantage of storing a complete copy of the XML document in memory at all times, allowing programmers to traverse ...

Get Special Edition Using XML, Second Edition 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.