开发者

3 approaches to work with XML

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 appro开发者_运维问答aches.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜