Event-Driven Models

[Previous] [Next]

The DOM provides a compact, easy-to-use set of interfaces for processing the contents of an XML document. However, sometimes using the DOM API is not the best approach. Suppose, for example, that you have a huge XML document to process. Because the DOM is a tree-based API, it does not allow you to process any of the document until the entire document is read successfully into the object. Event-driven APIs can report parsing events directly to the calling application, which can save a lot of processing time on large documents.

For example, suppose you need to get just the first few elements at the top of a document. Loading the entire document if you want to process only the first few elements wastes cycles. The event-driven model allows you to access the elements as the parser encounters them during processing. You can access an element in this manner whether or not an error lurks below. Remember that with the in-memory DOM API, an error in the last element of the document will render the entire document in error.

The tools that use this approach generate events that can be captured by rules. These rules then process the elements as they are encountered in the document.

One event-driven model that has been competing for the attention of developers is SAX, the Simple API for XML. SAX was developed by members of the XML-DEV mailing list, hosted by OASIS. In some ways, SAX is considered a competitor of DOM. However, I don't see it that way. Sometimes the DOM is more appropriate for a given situation, and sometimes SAX is more appropriate. In fact, Microsoft has begun to implement some features of SAX in the Microsoft XML Parser (MSXML). You can find out more about SAX at http://www.megginson.com/SAX/.

SAX is a great interface, but I want to concentrate on OmniMark, which is a more mature, event-driven, object model programming language. I'll describe OmniMark in detail in Appendix A.



XML and SOAP Programming for BizTalk Servers
XML and SOAP Programming for BizTalk(TM) Servers (DV-MPS Programming)
ISBN: 0735611262
EAN: 2147483647
Year: 2000
Pages: 150

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net