XML technologies / XML / Perl & XML / Event streams / The parser as a building block
(Excerpt from "Perl & XML" by Erik T. Ray & Jason McIntosh)
When implementing an XML processor, you do not have to separate the parser and handler, but doing so is usually beneficial. Modularization organizes your program better and makes it easier, for example, to test individual pieces of source code. The best modularization uses objects that communicate through dedicated channels and otherwise leave one another alone. It also makes software components easier to replace, which can be very important in XML processing.
We have already mentioned that an XML stream is an abstraction that decouples processing from the data source. Think of a tap somewhere in your garden that you use to water flowers or the lawn. Ultimately, its location does not matter as long as you can attach a hose and get water. There is nothing special about the hose either: as long as it has no holes and is long enough, it is fine. Whether it is made of plastic or rubber does not matter, nor does its color. In the same way, XML parser can be viewed as building blocks: you download one from the Internet, fit it into its intended place, and it works. The tricky part is connecting it correctly.
Returning to our example, the interesting part is where the tap is fitted. The tap has a standard diameter. All other taps have the same diameter if they conform to the same standard. XML event streams likewise need a standard interface. In recent years, XML developers have agreed on SAX. Until recently, Perl’s XML parsers were not interchangeable. Each had its own interface, making replacement difficult. This is increasingly changing as developers adopt SAX and agree on conventions for passing data from parsers to handlers. We will see some of the results in SAX .
Copyright © 2003 O'Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from the book "Perl & XML" is subject to the same conditions as the printed edition: the work and all its parts are protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
O’Reilly Verlag GmbH & Co. KG, Balthasarstraße 81, 50670 Köln, kommentar(at)oreilly.de
back to top