SAX and DOM

zhaozj2021-02-16  55

SAX is an event-based API for processing XML, SAX is a supplement to "document object model" or DOM

DOM is an object-based API for XML syntax analyzer published by W3C

SAX:

It is an event-based API. Operate on a lower level than the DOM. To provide you more control than DOM. Almost always more efficient than DOM. But unfortunately, you need more work than DOM.

As an object-based interface, DOM communicates with the application by building an object tree in memory. The object tree is an accurate mapping of the element tree in the XML file.

Dom is easy to learn and use because it matches the basic XML document. It is also ideal for applications I called XML (for example, browsers and editors). The XML-centric application manipulates the XML document in order to manipulate the XML document.

For applications that do not use XML, SAX is a wise choice. In fact, SAX does not explicitly build a document tree in memory. It allows applications to store data with the most efficient way.

Use SAX when you need more control; use DOM when you add convenience

The main reason for SAX is efficient. SAX is less than DOM, but provides more control over the grammar analyzer. Of course, if the work of the grammar analyzer is reduced, it means that you (developers) have more jobs. SAX is less resources that are consumed than DOM

The main limit of SAX is that it cannot browse the document backwards. In fact, after inspiring an event, the syntax analyzer will forget it. As you will see, the application must explicitly buffer the incidents of interest.

SAX, powerful APISAX is a standard and simple API for event-based syntax analyzers. SAX is an abbreviation for "Simple API for XML".

SAX was originally defined for Java, but it can also be used for Python, Perl, C and COM (Windows objects). There must be more language bindings in the future. Moreover, through COM, SAX syntax analyzer can also be used in all Windows programming languages, including Visual Basic and Delphi.

Some syntax analyzers that support SAX include Xerces, Apache Parser, MSXML (Microsoft Syntax Analyzer), and XDK (Oracle Syntax Analyzer). These grammar analyzers are the most flexible because they also support DOM.

Excerpted from http://www-900.ibm.com/developerWorks/cn/xml/x-saxapi/index.shtml

转载请注明原文地址:https://www.9cbs.com/read-19499.html

New Post(0)