PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Richard Munroe   Regular Expression Selection in Event Driven XML Parsing   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example of use
Class: Regular Expression Selection in Event Driven XML Parsing
Parse and search XML using regular expressions
Author: By
Last change:
Date: 17 years ago
Size: 2,088 bytes
 

Contents

Class file image Download
<?php

/**
 * @author Dick Munroe <munroe@csworks.com>
 * @copyright copyright @ 2006 by Dick Munroe, Cottage Software Works, Inc.
 * @license http://www.csworks.com/publications/ModifiedNetBSD.html
 * @version 1.0.0
 * @package saxyRE
 * @example ./example-backup.php
 * @example ./example-restore.php
 *
 * Quick and dirty XPATH like processing using regular expressions.
 *
 * To see thing in action execute:
 *
 * php example.php < example.xml > foo.html
 *
 * The GlobalValues nodes are stripped out.
 *
 * Edit History:
 *
 * Dick Munroe (munroe@csworks.com) 19-Apr-2006
 * Initial Version Created.
 */
include_once('class.saxyRE.php') ;

class
testSaxyRE
{
    var
$m_outputFile ;
    var
$m_parser ;

    function
testSaxyRE(
       
$theInputFile = 'php://stdin',
       
$theOutputFile = 'php://stdout')
    {
       
$theFileContents = file_get_contents($theInputFile) ;
       
$this->m_outputFile = fopen($theOutputFile, 'w') ;

       
$this->m_parser =
            new
saxyRe() ;

       
/*
         * Remove anything with GlobalValues in the path from parsing.
         */

       
$theRE =
            new
saxyREArgumentBlock(
               
'/GlobalValues/') ;

       
$this->m_parser->addRE($theRE) ;

       
$theRE =
            new
saxyREArgumentBlock(
               
'|^/|',
                array(&
$this, 'start'),
                array(&
$this, 'data'),
                array(&
$this, 'end')) ;

       
$this->m_parser->addRE($theRE) ;

       
$this->m_parser->parse($theFileContents) ;

       
fclose($this->m_outputFile) ;
    }

    function
start($theParser, $theName, $theAttributes)
    {
       
fwrite($this->m_outputFile, "<br /><b>Open tag:</b> " . $theName . "<br /><b>Attributes:</b> " . print_r($theAttributes, true) . "<br />");
    }

    function
data($theParser, $theText)
    {
       
fwrite($this->m_outputFile, "<br /><b>Text node:</b> " . $theText . "<br />");
    }

    function
end($theParser, $theName)
    {
       
fwrite($this->m_outputFile, "<br /><b>Close tag:</b> " . $theName . "<br />");
    }
}

$theParser = new testSaxyRE() ;
?>