From: priit at ww dot ee
Operating system: windows xp
PHP version: 5.0.5
PHP Bug Type: SimpleXML related
Bug description: XML parser adds stuff to value
Description:
------------
XML parser adds everything between the end of tag until start of next tag
to next tag's value. Yes, I can use trim() to fix this, but it still
doesnt feel right and more like workaround to fix sloppy parsing
error/bug.
Reproduce code:
---------------
<?php
$inputxml = '<?xml version="1.0" encoding="ISO-8859-1"?>
<info>
<aaa>111</aaa>
<ccc>222</ccc>
<bbb>333</bbb>
</info>
';
function startElement($parser, $name, $attrs) { $GLOBALS['temp_name'] =
$name; }
function endElement($parser, $name) { if($GLOBALS['temp_name']==$name)
$GLOBALS['moodul'] .= "(".$GLOBALS['temp_name']." :
'".$GLOBALS['temp_value']."')\n"; $GLOBALS['temp_value'] = ''; }
function characterData($parser, $data) { $GLOBALS['temp_value'] .= $data;
}
$moodul = htmlspecialchars($inputxml)."\n\n";
$temp_value='';
$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(!xml_parse($xml_parser, $inputxml)) {
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);
echo '<PRE>'.$moodul.'</PRE>';
?>
Expected result:
----------------
(AAA : '111')
(CCC : '222')
(BBB : '333')
Actual result:
--------------
(AAA : '
111')
(CCC : '
222')
(BBB : '
333')
--
Edit bug report at http://bugs.php.net/?id=34598&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=34598&r=trysnapshot4
Try a CVS snapshot (php5.0):
http://bugs.php.net/fix.php?id=34598&r=trysnapshot50
Try a CVS snapshot (php5.1):
http://bugs.php.net/fix.php?id=34598&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=34598&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=34598&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=34598&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=34598&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=34598&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=34598&r=support
Expected behavior: http://bugs.php.net/fix.php?id=34598&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=34598&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=34598&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=34598&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=34598&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=34598&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=34598&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=34598&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=34598&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=34598&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=34598&r=mysqlcfg