| FazBrowse Wikipedia Viewer | Main Page | | |
| Viewing: https://en.wikipedia.org/wiki/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> ¶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: