php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23631 xml_set_character_data_handler function called multiple times on one element
Submitted: 2003-05-14 16:08 UTC Modified: 2003-05-15 02:57 UTC
From: mrowe at pointsystems dot com Assigned:
Status: Not a bug Package: XML related
PHP Version: 4.3.1 OS: Win2k/RedHat Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mrowe at pointsystems dot com
New email:
PHP Version: OS:

 

 [2003-05-14 16:08 UTC] mrowe at pointsystems dot com
Hi there,

This may be a documentation issue, or an undocumented "feature."

When I parse some elements, the "character data handler" may get called multiple times.

Example:

// start code //
$xml = '<URL>http://www.php.net?a=1&amp;b=2&amp;c=3</URL>';
echo "xml = " . $xml . "\n\n";
$xml_parser = xml_parser_create(); 
xml_set_element_handler($xml_parser, "startElement", "endElement"); 
xml_set_character_data_handler($xml_parser, "characterData"); 
function startElement($parser, $tag, $attributes){ }
function endElement($parser, $tag){ }
function characterData($parser, $cdata){ 
	if (!trim($cdata)) return;
	echo "data = " . $cdata . "\n";
}
if (!xml_parse($xml_parser, $xml, true)){
	echo "not parsed";
}
// end code //

The results are:
data = http://slashdot.org?a=1
data = &
data = b=2
data = &
data = c=3

I'm expecting:
data = http://www.php.net?a=1&amp;b=2&amp;c=3

The online docs state "The second parameter, data, contains the character data as a string."  However, in each case, "data" is only PART of the character data.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-05-14 16:11 UTC] mrowe at pointsystems dot com
In the second paragraph, I should have stated:

"When I parse some elements, the "character data handler" may get called multiple times for a single XML element."

THANKS!
 [2003-05-15 02:57 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Basics of parsing with SAX parsers, not a bug, and it\'s entirely correct (it\'s even wanted :).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 06:01:29 2024 UTC