XML technologies / XML / Perl & XML / Event streams / Working with streams
(Excerpt from "Perl & XML" by Erik T. Ray & Jason McIntosh)
In computing, a data stream or stream is a sequence of data packets to process. For example, a text file is a sequence of characters, one per byte or possibly more, depending on the character and encoding. A program opens a file handle, creates a character stream, and can divide it into packets of one or more characters as needed. Streams can also be generated dynamically, for example by another program on another machine and sent over a network. A stream is an abstraction that treats the data source as irrelevant to subsequent processing.
A stream has the following characteristics:
It consists of a sequence of data fragments.
The order of those fragments matters.
The data source, such as a file or another program’s output, is irrelevant.
XML streams are simply preprocessed character streams. Their data fragments are called tokens (a term from parsing terminology) and consist of one or more characters. Each token is associated with a particular markup type: an element’s start-tag, end-tag, text data as a string, or a processing instruction. Splitting XML into these components is relatively simple for the parser and requires little time or resources.
XML streams differ from character streams in the importance of context. You cannot send an arbitrary sequence of tokens and expect an XML processor to make sense of it. Ten start-tags with no matching end-tags would not be very useful and certainly would not be well-formed XML. Malformed data is rejected. After all, XML aims to package data in a format that guarantees some integrity of document structure, does it not?
These context rules help both the parser and the processor. XML was designed with the parser in mind. Other markup languages require some lookahead. For example, SGML has no rule requiring end-tags. Determining where an element ends may be difficult or impossible for the parser. This makes the parser more complex, slower, and more memory-hungry.
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