PHP xml_set_object() Function

❮ PHP XML Parser Reference

Example

Use XML parser within an object:

<?php
class XMLParser
{
private $parser;

function __construct() {
  $this->parser = xml_parser_create();
  xml_set_object($this->parser, $this);
  xml_set_element_handler($this->parser, "start_tag", "end_tag");
  xml_set_character_data_handler($this->parser, "cdata");
}

function __destruct() {
  xml_parser_free($this->parser);
  unset($this->parser);
}

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

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

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

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

$xml_parser = new XMLParser();
$xml_parser->parse("<p id='test'>Hello World!</p>");
?>
Run Example »

Definition and Usage

The xml_set_object() function allows a XML parser to be used within an object.

Syntax

xml_set_object(parser, object)

Parameter Values

Parameter Description
parser Required. Specifies the XML parser to use
object Required. Specifies the object where to use the XML parser


Technical Details

Return Value: TRUE on success. FALSE on failure
PHP Version: 4.0+

❮ PHP XML Parser Reference
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.