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] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!