Package Proposal: XML_SaxFilters

From: Date: Sun, 22 Jun 2003 22:07:34 +0000
Subject: Package Proposal: XML_SaxFilters
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-17627@lists.php.net to get a copy of this message
Hi All, Following on from XML_HTMLSax, XML_SaxFilters is a framework to make parsing simple XML documents easy and complex documents possible. The code was based on Luis Aegerich's SaxFilters classes (http://phpxmlclasses.sourceforge.net/show_doc.php?class=class_sax_filters.html) and Luis has given permission to change the license to the PHP license for inclusion in PEAR. I've made alot of modifications though so it no longer looks that much like the original. There's some explaination of what Sax Filtering is at; http://www.cafeconleche.org/books/xmljava/chapters/ch08.html (Java) http://www-106.ibm.com/developerworks/xml/library/x-tipsaxflex.html (Python) http://www.xml.com/pub/a/2001/10/10/sax-filters.html (Perl) Some of the things that can be done with SaxFilters (you'd need to write your own filters of course); - makes parsing XML documents "modular" - you define your own (usually minimalistic) filter "plugin" and away you go. - makes it possible to parse documents where the precise structure was known in advance, such as an (X)HTML document, where the depth in nodes may vary significantly from document to document. - "compiling" templates (see template.php example) - parsing WSDL documents to generate proxy classes (this could be useful for REST based web services where HTTP encoding it used) - transforming XML (see xml2html): doing so it probably more exhaustive coding-wise than XSLT but might suit people who don't have the XSLT extension or just don't like XSL. - building PDF documents from XML based content (with help from a PDF generator of course) - launch PHP-GTK apps from XUL (I uses Luis's version to do so here: http://www.phppatterns.com/index.php/article/articleview/48/1/2/) - anything else you can think of The code is intended as a framework for people to add to, when dealing with specific problems, so there's alot of abstraction (in particular the "Interface" classes which do nothing but define APIs). In general Sax Filtering is probably not something you'd do at the point a visitor requests a page (it would be slow for a complex XML document) but rather for a "compile" stage, similar Smarty which compiles templates into native PHP. A PEAR-packaged version of the code is available at: http://www.phppatterns.com/index.php/filemanager/fileview/29/ Source code; Examples; http://code.phppatterns.com/XML_SaxFilters/docs/examples/simple.phps http://code.phppatterns.com/XML_SaxFilters/docs/examples/rssfilter.phps http://code.phppatterns.com/XML_SaxFilters/docs/examples/xml2html.phps http://code.phppatterns.com/XML_SaxFilters/docs/examples/template.phps Classes; http://code.phppatterns.com/XML_SaxFilters/XML_SaxFilters.phps http://code.phppatterns.com/XML_SaxFilters/SaxFilters/AbstractParser.phps http://code.phppatterns.com/XML_SaxFilters/SaxFilters/ParserInterface.phps http://code.phppatterns.com/XML_SaxFilters/SaxFilters/ExpatParser.phps http://code.phppatterns.com/XML_SaxFilters/SaxFilters/HTMLSaxParser.phps - (an concrete parser that uses XML_HTMLSax - i.e. can apply SaxFilters to badly formed XML) http://code.phppatterns.com/XML_SaxFilters/SaxFilters/AbstractFilter.phps http://code.phppatterns.com/XML_SaxFilters/SaxFilters/FilterInterface.phps http://code.phppatterns.com/XML_SaxFilters/SaxFilters/ReaderInterface.phps http://code.phppatterns.com/XML_SaxFilters/SaxFilters/FileReader.phps http://code.phppatterns.com/XML_SaxFilters/SaxFilters/StringReader.phps http://code.phppatterns.com/XML_SaxFilters/SaxFilters/StructReader.phps http://code.phppatterns.com/XML_SaxFilters/SaxFilters/WriterInterface.phps http://code.phppatterns.com/XML_SaxFilters/SaxFilters/FileWriter.phps http://code.phppatterns.com/XML_SaxFilters/SaxFilters/StringWriter.phps http://code.phppatterns.com/XML_SaxFilters/SaxFilters/StructWriter.phps Anyway - hope that's interesting. All the best, Harry

« previous php.pear.dev (#17627) next »