Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 0.3.4

Bug #1687 Function addArray() generates incorrectly designed XML document
Submitted: 2004-06-20 19:03 UTC
From: fog at yandex dot ru Assigned: ifeghali
Status: Closed Package: XML_sql2xml
PHP Version: Irrelevant OS:
Roadmaps: (Not assigned)    
Subscription  


 [2004-06-20 19:03 UTC] fog at yandex dot ru
Description: ------------ Function addArray() generates incorrectly designed XML document out of not associative arrays. code $a = array('apple', 'orange', 'pear'); $xml->addArray($a); $xml->getXML(); returns incorrect formed XML document, without error reporting <?xml version="1.0"?> <root> <result> <0>apple</0> <1>orange</1> <2>pear</2> </result> </root> I think there should be either an error alert or array processing with the similar function before generating xml document. function prepare_xml_array($array, $key_name = 'index_', $suffix = '_') { if (!is_array($array)) { return false; } $array_new = array(); foreach($array as $key=>$val) { if (!is_string($key)) { $key = $key_name.$key; while (array_key_exists($key, $array)) { $key .= $suffix; } } if (is_array($val)) { $array_new[$key] = prepare_xml_array($val); } else { $array_new[$key] = $val; } } return $array_new; } Reproduce code: --------------- $a = array('apple', 'orange', 'pear'); $xml->addArray($a); $xml->getXML(); Expected result: ---------------- some thing like <?xml version="1.0"?> <root> <result> <i0>apple</i0> <i1>orange</i1> <i2>pear</i2> </result> </root> Actual result: -------------- <?xml version="1.0"?> <root> <result> <0>apple</0> <1>orange</1> <2>pear</2> </result> </root>

Comments

 [2008-03-23 23:11 UTC] ifeghali (Igor Feghali)
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.