FazBrowse Wikipedia Viewer | Main Page |
Search Wikipedia:
|
Viewing: https://en.wikipedia.org/wiki/Simple_API_for_XML

Simple API for XML

Contents
See also
References
Further reading

SAX (Simple API for XML) is an event-driven online algorithm for lexing and parsing XML documents, with an API developed by the XML-DEV mailing list. SAX provides a mechanism for reading data from an XML document that is an alternative to that provided by the Document Object Model (DOM). Where the DOM operates on the document as a whole—building the full abstract syntax tree of an XML document for convenience of the user—SAX parsers operate on each piece of the XML document sequentially, issuing parsing events while making a single pass through the input stream.

<?xml version="1.0" encoding="UTF-8"?> <DocumentElementparam="value"> <FirstElement> &#xb6;SomeText </FirstElement> <?some_pi some_attr="some_value"?> <SecondElementparam2="something"> Pre-Text<Inline>Inlinedtext</Inline>Post-text. </SecondElement> </DocumentElement>

This XML document, when passed through a SAX parser, will generate a sequence of events like the following:

Note that the first line of the sample above is the XML Declaration and not a processing instruction; as such it will not be reported as a processing instruction event (although some SAX implementations provide a separate event just for the XML declaration).

The result above may vary: the SAX specification deliberately states that a given section of text may be reported as multiple sequential text events. Many parsers, for example, return separate text events for numeric character references. Thus in the example above, a SAX parser may generate a different series of events, part of which might include:

See also

edit

References

edit
"Simple API for XML". oracle.com. ORACLE. Retrieved 2011-05-02. Note: In a nutshell, SAX is oriented towards state independent processing, where the handling of an element does not depend on the elements that came before. StAX, on the other hand, is oriented towards state dependent processing. For a more detailed comparison, see SAX and StAX in Basic Standards and When to Use SAX.
  • ↑ Charlie, Frank (February 2001). "XML Parsers: DOM and SAX Put to the Test". devX. Retrieved 2011-10-20. Although these tests do not show it, SAX parsers typically are faster for very large documents where the DOM model hits virtual memory or consumes all available memory.
  • Further reading

    edit

    View original on Wikipedia | Back | FazBrowse Home