topical media & game development
server-php-xml-class-sax-filters-class-sax-filters.php / php
<?
// # # # # # # # # # # # # # # # # # # # ###
// Title : Sax Filters
// Version : 1.0
// Author : Luis Argerich (lrargerich@yahoo.com)
// Last modification date : 05-20-2002
// Description : A set of classes defining interfaces for generic SAX
// parsers as well as SAX filters.
// # # # # # # # # # # # # # # # # # # # ###
// History:
// 05-15-2002 : First version of this class.
// # # # # # # # # # # # # # # # # # # # ###
// To-Dos:
// Improve the Expat SAX parser class to process PI's and other not-so-common
// XML nodes.
// # # # # # # # # # # # # # # # # # # # ###
// How to use it:
// Read the documentation in sax_filters.html
// # # # # # # # # # # # # # # # # # # # ###
// CHECK FOR DOUBLE DEFINITION HERE
if(defined("_class_sax_filters_is_included")) {
// do nothing since the class is already included
} else {
define("_class_sax_filters_is_included",1);
class AbstractStreamer {
function stream(data) {
print(listener;
function AbstractSAXParser() {}
function parserSetoption(val) {}
function setListener(this->listener=parser,attribs) {
name,parser,this->listener->endElementHandler(parser,this->listener->characterDataHandler(listener;
function setListener(this->listener=name,name) {}
function characterDataHandler(parser;
var buffer;
var line;
function ExpatParser(this->filename=this->parser=xml_parser_create();
this->parser,&this->parser,"startElementHandler","endElementHandler");
xml_set_character_data_handler(opt,this->parser, val);
}
function parse() {
if (!(this->filename, "r"))) {
return 0;
}
while (fp, this->parser, fp))) {
xml_parser));
xml_parser);
die("Error: ".this->line);
}
}
xml_parser_free(flag=0;
function startElementHandler(attribs) {
if(strtolower(this->flag=1;
} else {
this->listener->startElementHandler(attribs);
}
function endElementHandler(name)=="name") {
this->listener->endElementHandler(data) {
if(data=strtoupper(this->listener->characterDataHandler(flag=0;
function startElementHandler(attribs) {
if(strtolower(this->flag=1;
} else {
this->listener->startElementHandler(attribs);
if(this->listener->startElementHandler("b",array());}
}
function endElementHandler(name)=="name") {
this->listener->endElementHandler("b");
}
name);
}
function characterDataHandler(this->flag) {
data);
}
data);
}
}
class FilterStreamer extends AbstractFilter {
var obj) {
obj;
}
function startElementHandler(attribs) {
name");
foreach(key => this->stream->stream(" val'");
}
name) {
name>");
}
function characterDataHandler(this->stream->stream("name,name");
foreach(key => key='name) {
print("</data) {
print("
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.