ID:               34591
 Updated by:       [EMAIL PROTECTED]
 Reported By:      priit at ww dot ee
-Status:           Feedback
+Status:           Bogus
 Bug Type:         XML related
 Operating System: Windows XP SP2
 PHP Version:      5.0.5
 New Comment:

Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

It's a bad idea to assume that all the data associated with a
particular element is returned to you in a single function call to your
characterData() handler, which is what you're doing here. What is
happening is that characterData() is being called more than once for
the same element, and you're overwriting the global $temp_value
variable every time.

Making these changes to your code makes it work just fine for me on
5.1:

function endElement($parser, $name)
    {
    global $temp_name,$temp_value,$moodul;
    if($temp_name==$name) {$moodul .= "($temp_name : $temp_value)\n";}
    $temp_value = '';
    }

function characterData($parser, $data)
    {
    global $temp_value;
    $temp_value .= $data;
    }




Previous Comments:
------------------------------------------------------------------------

[2005-09-22 13:48:41] [EMAIL PROTECTED]

Well, then try to provide really complete reproduce script?
I doubt that "$file = 'failid/kontakt.xml'; .." will work without the
.xml file.

------------------------------------------------------------------------

[2005-09-22 13:37:50] priit at ww dot ee

...

------------------------------------------------------------------------

[2005-09-21 23:38:27] priit at ww dot ee

charset has nothing to do with it. I tried converting the input to
latin1 first and utf8 and changed the xml_parser_create charset
accordingly, but the result was the same always! the characters in my
example xml are compatible with ISO-8859-1 although the xml input it
sayd to be ISO-8859-15 ... if I changed the xml itself also to
something else the result was still the same.

------------------------------------------------------------------------

[2005-09-21 23:35:56] priit at ww dot ee

<?php
$file = 'failid/kontakt.xml';

function startElement($parser, $name, $attrs)
    {
    global $temp_name;
    $temp_name = $name;
    }

function endElement($parser, $name)
    {
    global $temp_name,$temp_value,$moodul;
    if($temp_name==$name) {$moodul .= "($temp_name : $temp_value)\n";}
    }

function characterData($parser, $data)
    {
    global $temp_value;
    $temp_value = $data;
    }

$moodul = '<PRE>';
$xml_parser = xml_parser_create('ISO-8859-1');
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
if (!($fp = fopen($file, "r"))) { die("could not open XML input"); }
$data = fread($fp, filesize($file));
if(!xml_parse($xml_parser, $data, feof($fp)))
    {
    die(sprintf("XML error: %s at line %d",
    xml_error_string(xml_get_error_code($xml_parser)),
    xml_get_current_line_number($xml_parser)));
    }

xml_parser_free($xml_parser);
$moodul .= '</PRE>';

echo $moodul;

?>

------------------------------------------------------------------------

[2005-09-21 23:17:34] [EMAIL PROTECTED]

Try using compatible charset.


------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/34591

-- 
Edit this bug report at http://bugs.php.net/?id=34591&edit=1

Reply via email to