php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #34598 SimpleXML parser adds stuff to value
Submitted: 2005-09-22 15:15 UTC Modified: 2005-09-22 15:20 UTC
From: priit at ww dot ee Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.0.5 OS: windows xp
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: priit at ww dot ee
New email:
PHP Version: OS:

 

 [2005-09-22 15:15 UTC] priit at ww dot ee
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')

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-09-22 15:20 UTC] priit at ww dot ee
...
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 02:01:28 2024 UTC