We modified Zend_Config_Ini to allow the use of numeric keys. I wonder if there's something similar we can do here?

I've made a small patch if you're interested:-

Zend/Config/Xml.php
===================================================================
--- Xml.php     (revision 6921)
+++ Xml.php     (working copy)
@@ -137,10 +137,18 @@
         if (count($xmlObject->children())) {
             foreach ($xmlObject->children() as $key => $value) {
                 if ($value->children()) {
-                    $config[$key] = $this->_toArray($value);
+                    $value = $this->_toArray($value);
                 } else {
-                    $config[$key] = (string) $value;
+                    $value = (string) $value;
                 }
+                if (isset($config[$key])) {
+                    if (!is_array($config[$key])) {
+                        $config[$key] = array($config[$key]);
+                    }
+                    $config[$key][] = $value;
+                } else {
+                    $config[$key] = $value;
+                }
             }
         } else  {
             // object has no children: it's a string

Essentially it looks for existing keys whilst the array is being built - if the key already exists it transforms the value into a numeric array instead of a string value.

I tested it with the following config:-

<root>
    <foo>
        <bar>Item 1</bar>
        <bar>Item 2</bar>
        <bar>Item 3</bar>
        <bar>Item 4</bar>
        <bar>Item 5</bar>
        <item>3</item>
        <item>2</item>
        <mail>
            <name>My name</name>
        </mail>
    </foo>
</root>

...and it gives the following output:-

Zend_Config Object
(
    [_allowModifications:protected] =>
    [_index:protected] => 0
    [_count:protected] => 3
    [_data:protected] => Array
        (
            [bar] => Zend_Config Object
                (
                    [_allowModifications:protected] =>
                    [_index:protected] => 0
                    [_count:protected] => 5
                    [_data:protected] => Array
                        (
                            [0] => Item 1
                            [1] => Item 2
                            [2] => Item 3
                            [3] => Item 4
                            [4] => Item 5
                        )

                    [_loadedSection:protected] =>
                    [_extends:protected] => Array
                        (
                        )

                )

            [item] => Zend_Config Object
                (
                    [_allowModifications:protected] =>
                    [_index:protected] => 0
                    [_count:protected] => 2
                    [_data:protected] => Array
                        (
                            [0] => 3
                            [1] => 2
                        )

                    [_loadedSection:protected] =>
                    [_extends:protected] => Array
                        (
                        )

                )

            [mail] => Zend_Config Object
                (
                    [_allowModifications:protected] =>
                    [_index:protected] => 0
                    [_count:protected] => 1
                    [_data:protected] => Array
                        (
                            [name] => My name
                        )

                    [_loadedSection:protected] =>
                    [_extends:protected] => Array
                        (
                        )

                )

        )

    [_loadedSection:protected] =>
    [_extends:protected] => Array
        (
        )

)

Hope this is helpful


There are several mismatches between INI and XML formats, so it's no
surprise that we must treat each a bit differently. How would having
multiple values work in INI, or would we not support this?

Numeric tag names make illegal XML, so we already have functionality in
Zend_Config_Ini that is not supported with Zend_Config_Xml.

In principle, I have no objection to adding such support.

Thanks, Rob!

--

Simon Mundy | Director | PEPTOLAB

""" " "" """""" "" "" """"""" " "" """"" " """"" "  """""" "" "

PeptoLab will be closed:
Saturday 15th  December through until Monday 17th December
Saturday 22nd December through until Wednesday 2nd January
For urgent requests, please call 0438 046 061

202/258 Flinders Lane | Melbourne | Victoria | Australia | 3000
Voice +61 (0) 3 9654 4324 | Mobile 0438 046 061 | Fax +61 (0) 3 9654 4124
http://www.peptolab.com

Reply via email to