PhpDig.net

What is PhpDig?
PhpDig is a PHP MySQL based
Web Spider & Search Engine.




xslt_set_sax_handler

Name

xslt_set_sax_handler — Assigns SAX handlers for parsing events.

Synopsis

void xslt_set_sax_handler(xslt_handle, handler_list);
resource xslt_handle: Handle to the Sablotron parser to use
array handler_list: List of SAX handlers

Returns

void

Description

Sets 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:

document

Provide an array containing the names of the handler functions for document start and end events. These handlers will be passed one argument: the Sablotron parser handle on which the event occurred.

element

Provide an array containing the names of the handler functions for element start and end events. The start handler will be passed three arguments: the Sablotron parser handle on which the event occurred, the name of the element encountered, and an associative array containing the element's attributes. The attribute names will be the array keys, and the attribute values will be the array values. The end handler will be passed two arguments: the Sablotron parser handle on which the event occurred, and the name of the element in question.

namespace

Provide an array containing the names of the handler functions for namespace start and end events. The start handler will be passed three arguments: the Sablotron parser handle on which the event occurred, the namespace prefix string, and the URI string. The end handler will be passed two arguments: the Sablotron parser handle on which the event occurred, and the namespace prefix string.

comment

Provide a string containing the name of the handler function for comment events. The handler will be passed two arguments: the Sablotron parser handle on which the event occurred, and the contents of the comment.

pi

Provide a string containing the name of the handler function for processing instruction events. The handler will be passed three arguments: the Sablotron parser handle on which the event occurred, the target, and the contents.

characters

Provide a string containing the name of the handler function for character data events. The handler will be passed two arguments: the Sablotron parser handle on which the event occurred, and the contents of the character data.



Example

Example 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.

Powered by: vBulletin Version 3.0.7
Copyright ©2000 - 2005, Jelsoft Enterprises Ltd.
Copyright © 2001 - 2005, ThinkDing LLC. All Rights Reserved.