xslt_set_sax_handlerDescriptionSets SAX handlers for parsing of XML on a given Sablotron handle. handler_list is an associative array. Each key of the array must be one of the supported event types from the list below; the value of each array element is either an array containing the names of the start and end handlers for the event, or a string containing the name of the event handler if that event does not support separate handlers for start and end events. Supported events are:
ExampleExample 1146. Setting up SAX handlers
<?php
error_reporting(E_ALL);
/* Define the handler functions. */
function doc_start($xslt) {
echo "<hr>Document start encountered on parser handle '$xslt'\n";
}
function doc_end($xslt) {
echo "<hr>Document end encountered on parser handle '$xslt'\n";
}
function element_start($xslt_handle, $element, $attributes) {
echo "<hr>Got element '$element'. ";
if (count($attributes)) {
echo "Attributes:\n";
print_r($attributes);
} else {
echo "No attributes.";
}
}
function cdata($xslt_handle, $contents) {
echo "Got character data '$contents'\n";
}
/* Create the array of events => handler names. */
$sax_handlers = array('document' => array('doc_start', 'doc_end'),
'element' => array('element_start'),
'characters' => 'cdata');
/* Create the parser and set the handlers on it. */
$xslt = xslt_create();
xslt_set_sax_handler($xslt, $sax_handlers);
/* Run the parser and display the results if successful. */
$result_URI = 'arg:/my_buffer';
if (!xslt_run($xslt, 'slashdot.xsl', 'slashdot.xml', $result_URI)) {
echo "<pre>xslt_run() failed:" . xslt_error() . "\n";
} else {
echo xslt_fetch_result($xslt, $result_URI);
}
xslt_free($xslt);
?>
PHP Functions Essential Reference. Copyright © 2002 by New Riders Publishing
(Authors: Zak Greant, Graeme Merrall, Torben Wilson, Brett Michlitsch).
This material may be distributed only subject to the terms and conditions set forth
in the Open Publication License, v1.0 or later (the latest version is presently available at
http://www.opencontent.org/openpub/).
The authors of this book have elected not to choose any options under the OPL. This online book was obtained
from http://www.fooassociates.com/phpfer/
and is designed to provide information about the PHP programming language, focusing on PHP version 4.0.4
for the most part. The information is provided on an as-is basis, and no warranty or fitness is implied. All
persons and entities shall have neither liability nor responsibility to any person or entity with respect to
any loss or damage arising from the information contained in this book.
|