tags:

views:

66

answers:

1

I need to use different approaches when working with XML - LINQ to XML, streaming, DOM.
Can anybody give me examples of this approaches?
I just want to see what's the difference between this approaches.

+1  A: 

Not sure about Linq, but streaming vs. dom are different in that a DOM approach parses entire XML documents in to memory before the user-level API becomes active, while the stream based approach raises "events" during the low-level parsing routine. Consider what would happen if you processed a long XML file with a syntax error at the very end of the file, with DOM vs. Streamed; the DOM based approach would error before your program could "get at the data", while the streamed based approach would have already generated a long list of events before the error gets thrown.

The DOM approach means the API can do "whole document lookups", for example in DOM/Xpath you can say "//div" to mean "all div elements in the document", this is much harder / impossible in a streamed approach. On the other hand, streamed processing tends to use less memory, as only a small part of the XML document needs to be held in memory at one time.

Examples of APIs using these approaches are SAX/XmlReader for stream based, DOM/XSLT for DOM based.

Robin