Heey Cakers...
i have found a error in the XML class of CakePHP. I've the following
xml data
<lst name="Address.city_s">
<int name="Amsterdam">2</int>
<int name="Den Haag">1</int>
<int name="Rotterdam">1</int>
<int name="Einhoven">2</int>
</lst>
when i parse this data with the xml class to a array
$xml = new XML($data);
$array = $xml->toArray();
i got a this array back
Array
(
[Lst] => Array
(
[name] => Address.city_s
[int] => Array
(
[value] => 1
[name] => Rotterdam
)
[Int] => Array
(
[0] => Array
(
[value] => 2
[name] => Amsterdam
)
[1] => Array
(
[value] => 1
[name] => Den Haag
)
[2] => Array
(
[value] => 2
[name] => Einhoven
)
)
)
)
Notice that the 3th element has got a different name and is put in a
different subarray. The strange part is that is allways the 3e elment
of a xml data.
I have looked in the source code of the XML class, but i can't find
the error.
Is there someone that could help me?? At the moment i'm stuck on this
error and not getting forward. Sorry for the bad englisch, that is
also a point i could make progress on.
Thank you in advance all ready
function toArray($object = null) {
665 if ($object === null) {
666 $object =& $this;
667 }
668 if (is_a($object, 'XmlNode')) {
669 $out = $object->attributes;
670 $multi = null;
671 foreach ($object->children as $child) {
672 $key = Inflector::camelize($child->name);
673 if (is_a($child, 'XmlTextNode')) {
674 $out['value'] = $child->value;
675 continue;
676 } elseif (isset($child->children[0]) &&
is_a($child->children[0], 'XmlTextNode')) {
677 $value = $child->children[0]->value;
678 if ($child->attributes) {
679 $value = array_merge(array('value' =>
$value), $child->attributes);
680 }
681 if (isset($out[$child->name])) {
682 if (!isset($multi)) {
683 $multi = array($key =>
array($out[$child->name]));
684 unset($out[$child->name]);
685 }
686 $multi[$key][] = $value;
687 } else {
688 $out[$child->name] = $value;
689 }
690 continue;
691 } else {
692 $value = $this->toArray($child);
693 }
694 if (!isset($out[$key])) {
695 $out[$key] = $value;
696 } else {
697 if (!is_array($out[$key]) || !isset($out[$key]
[0])) {
698 $out[$key] = array($out[$key]);
699 }
700 $out[$key][] = $value;
701 }
702 }
703 if (isset($multi)) {
704 $out = array_merge($out, $multi);
705 }
706 }
707 return $out;
708 }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---