|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-09-22 15:20 UTC] priit at ww dot ee
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 09 03:00:01 2025 UTC |
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')