note 35177 added to function.xml-set-character-data-handler
| From: | wiart at yahoo dot com | Date: | Fri, 22 Aug 2003 10:31:55 +0000 |
| Subject: | note 35177 added to function.xml-set-character-data-handler | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-54859@lists.php.net to get a copy of this message | ||
WARNING !!!
Always use concatenation for getting the content of a XML tag when you write the function that will
deal with the Character Data handling
Example:
$mycontent = '';
$xml_parser = xml_parser_create ();
xml_set_character_data_handler($xml_parser, "_characterdata");
function _characterdata($parser, $data){
global $mycontent;
//HERE: use .= and not =
$mycontent .= $data;
}
...
while ($data = fread($fp, 4096)) {
xml_parse($xml_parser, $data, feof($fp));
}
I had the following problem with the use of '=$data' :
In one of my XML documents, the parsing stopped in the middle of a character data :
In original document:
<prop name="nbres">100</prop>
What happened:
<prop name="nbres">10[parsing stopped here in chunck of 4096bytes]0</prop>
As I did not use the concatenation, when I displayed the value of the 'nbres' property,
the value was 0 instead of 100 because the first time the function characterdata was called :
$mycontent = 10;
and the second time:
$mycontent = 0; //!!!!!!!!!!!!! HO HO !! some problem occured ...
Instead of $mycontent = 100;
CONCLUSION:
IN YOUR CHARACTER DATA HANDLER FUNCTIONS, NEVER FORGET THE . (concatenation operator) !!!!! IF YOU
DON'T WANT TO HAVE WEIRD BUGS SOME TIMES
----
Manual Page -- http://www.php.net/manual/en/function.xml-set-character-data-handler.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+35177
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+35177&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+35177&report=yes