★ wanayoo — archive 1999 http://www.php.net/manual/de/function.xml-set-object.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to XML
Quick Reference
English version of this pageJapanese version of this pageItalian version of this pageFrench version of this pageHungarian version of this page
XML
* xml_parser_create
* xml_set_object
* xml_set_element_handler
* xml_set_character_data_handler
* xml_set_processing_instruction_handler
* xml_set_default_handler
* xml_set_unparsed_entity_decl_handler
* xml_set_notation_decl_handler
* xml_set_external_entity_ref_handler
* xml_parse
* xml_get_error_code
* xml_error_string
* xml_get_current_line_number
* xml_get_current_column_number
* xml_get_current_byte_index
* xml_parser_free
* xml_parser_set_option
* xml_parser_get_option
* utf8_decode
* utf8_encode
Manual: xml_set_object
View the source code for this pageSearch the site



Previous page
 xml_parser_create
 Updated
Mon, 14 Aug 2000
xml_set_element_handler 
Next page


xml_set_object

(PHP4 >= 4.0b4)

xml_set_object -- Use XML Parser withing an object

Description

void xml_set_object (int parser, object &object)

This function makes parser useable from within object. All callback functions settet via xml_set_element_handler() etc are assumed to be methods of object.


<?php
class xml  {
var $parser;

function xml() {
    $this->parser = xml_parser_create();
    xml_set_object($this->parser,&$this);
    xml_set_element_handler($this->parser,"tag_open","tag_close");
    xml_set_character_data_handler($this->parser,"cdata");
}

function parse($data) { 
    xml_parse($this->parser,$data);
}

function tag_open($parser,$tag,$attributes) { 
    var_dump($parser,$tag,$attributes); 
}

function cdata($parser,$cdata) { 
    var_dump($parser,$cdata);
}

function tag_close($parser,$tag) { 
    var_dump($parser,$tag); 
}

} // end of class xml

$xml_parser = new xml();
$xml_parser->parse("<A ID=\"hallo\">PHP</A>");
?>
   

Anmerkung: xml_set_object() handling was added in PHP 4.0.


User Contributed Notes: xml_set_object


cleong@organic.com
21-Mar-2000 07:41
In regards to the example above, where is xml_parser_free() called? Seems like it's a bad idea to allocate resource in a constructor, since PHP objects have no destructor.


robert@webmotion.com
18-Apr-2000 10:58
While true that there is no automatic destructor for PHP class objects, it is quite simple to create a method called destroy and perform the destruction manually. In the example above it may not be necessary to free the xml parser immediately... it would appear from the example that the object is re-useable.


 About Notes


Previous page
 xml_parser_create
 Updated
Mon, 14 Aug 2000
xml_set_element_handler 
Next page





Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.