XML is a format commonly used for the interchange of data between software applications.
The easiest way to process data in XML format is by means of some procedure that reads the whole document into a data structure native to the programming language used. In PHP, the result would be an associative array of pairs (key,value). Each of the values in the array, in turn, would be an associative array, or a primitive value of numeric or string type.
But sometimes, the file holding the XML document may be up to several GBytes in size, and the volume of data to be processed is too big to hold the entire document in memory. In those cases, the file must be processed as a stream: Elements in the file need to be read an processed one element at a time.
This post explains how to work in PHP with large XML documents, by reading them as streams.
Continue reading »