Currently, there are two major methodologies behind XML parsing. First is a group of parsers built to conform to the Document Object Model (DOM) standard. Second is another group of parsers built to conform to the Simple API for XML (SAX) standard. The DOM-based parsers generate a tree of objects in memory based on the structure and contents of the XML data. This enables you to walk through the tree and access information or access only a portion (or branch) of your XML data. SAX-based parsers take a different approach to parsing ”they are event-driven. An event-driven XML parser module searches through XML data and looks for particular patterns (for example, the start of an element, the end of an element, and so forth). If the pattern is found in the XML data, the parser calls a callback function and passes pertinent data as arguments to the function. Typically, a separate callback function is defined for each pattern in the XML data that we're interested in, which varies based on each particular application. I'll present examples that show how to define callback functions that match the different important patterns contained in XML data. A notional event-based parser is shown in Figure 3.1. Figure 3.1. Notional event-based XML parser.
|