Source for file chained.php
Documentation is available at chained.php
* Shows two filters chained together
# require_once 'XML/SaxFilters.php'; // This is the normal way to do it
# Done to help development
if ( !@include_once 'XML/SaxFilters.php' ) {
define ('XML_SAXFILTERS', '../../');
include_once XML_SAXFILTERS . 'SaxFilters.php';
//---------------------------------------------------------------------
* Make a seperate class for both filters to write output to
function writeLine ($text) {
$this->output.= $this->indent. $text. "\n";
function removeIndent () {
//---------------------------------------------------------------------
// Filters for Language tag
/* implements XML_SaxFilters_FilterInterface */
function open(& $tag,& $attribs) {
$this->child->open ($tag,$attribs);
if ( $tag == 'language' ) {
if ( !isset ($attribs['name']) ) $attribs['name'] = 'Unknown';
if ( !isset ($attribs['version']) ) $attribs['version'] = 'Unknown';
$this->Output->writeLine ($attribs['name']. ' version '. $attribs['version']);
$this->child->close ($tag);
if ( $tag == 'language' ) {
$this->Output->removeIndent ();
// Character data handler
if ( !$this->child->data ($data) ) {
$this->Output->writeLine ($data);
//---------------------------------------------------------------------
/* implements XML_SaxFilters_FilterInterface */
function open(& $tag,& $attribs) {
// Character data handler
$this->Output->writeLine ($data);
//---------------------------------------------------------------------
<dynamically_typed_languages>
<language name="PHP" version="4.3.2">
PHP is number 1 for building web based applications.
<url>http://www.php.net</url>
<language name="Python" version="2.2.3">
Python is number 1 for cross platform desktop applications.
<url>http://www.python.org</url>
<language name="Perl" version="5.8.0">
Perl is number 1 for text and batch processing.
<url>http://www.perl.org</url>
</dynamically_typed_languages>
//---------------------------------------------------------------------
// This is where the action takes place
// Create the parser (use native SAX extension, StringReader, XML document)
// Create the instance of Output
// Add the UrlFilter to the LanguageFilter
// Add the LanguageFilter to the parser
if ( ! $parser->parse () ) {
$error = $parser->getError ();
echo $error->getMessage ();
echo '<pre>'. $Output->fetch (). '</pre>';
Documentation generated on Mon, 11 Mar 2019 10:15:10 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|