note 85415 modified in function.xml-set-character-data-handler by felipe
| From: | felipe@php.net | Date: | Sun, 07 Sep 2008 14:49:29 +0000 |
| Subject: | note 85415 modified in function.xml-set-character-data-handler by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-144223@lists.php.net to get a copy of this message | ||
To detect that concatenation of data is taking place, you can keep track of whether the last
function call was to the data processing function.
e.g. using $this->inside_data variable below:
<?php
xml_set_element_handler($this->parser, "start_tag", "end_tag");
xml_set_character_data_handler($this->parser, "contents");
protected function contents($parser, $data)
{
switch ($this->current_tag) {
case "name":
if ($this->inside_data)
$this->name .= $data; // need to concatenate data
else
$this->name = $data;
break;
...
}
$this->inside_data = true;
}
protected function start_tag($parser, $name)
{
$this->current_tag = $name;
$this->inside_data = false;
}
protected function end_tag() {
$this->current_tag = '';
$this->inside_data = false;
}
?>
--was--
To detect that concatenation of data is taking place, you can keep track of whether the last
function call was to the data processing function.
e.g. using $this->inside_data variable below:
xml_set_element_handler($this->parser, "start_tag", "end_tag");
xml_set_character_data_handler($this->parser, "contents");
protected function contents($parser, $data)
{
switch ($this->current_tag) {
case "name":
if ($this->inside_data)
$this->name .= $data; // need to concatenate data
else
$this->name = $data;
break;
...
}
$this->inside_data = true;
}
protected function start_tag($parser, $name)
{
$this->current_tag = $name;
$this->inside_data = false;
}
protected function end_tag() {
$this->current_tag = '';
$this->inside_data = false;
}
http://php.net/manual/en/function.xml-set-character-data-handler.php