generating an object from XMl using Zend_Config_Xml

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Dear all

I have the following XMl document, that I parse and generate from it an
object using Zend_Config_Xml:

<?xml version="1.0" encoding="UTF-8"?>
<configdata>
                <category>
                               <name>Categoria</name>
                               <groups>
                                               <group>
                                                               <name>Grupo 1
</name>
                                               </group>
                                               <group>
                                                              <name>Grupo 2
</name>
                                               </group>
                               </groups>
                </categoria>
</configdata>

$category = *new* Zend_Config_Xml(*'category.xml'*,*'category'*) ;

print_r($category->toArray());**

the result is:
Array
(
    [name] => Categoria
    [grupos] => Array
        (
            [grupo] => Array
                (
                    [0] => Array
                        (
                           [name] => Grupo 1
                        )
                    [1] => Array
                        (
                            [name] => Grupo 2
                        )
                )
       )
)

Till here, everything is fine, I do get what I want. But in the case I have
only one group in groups, the result is different.

<?xml version="1.0" encoding="UTF-8"?>
<configdata>
                <category>
                               <name>Categoria</name>
                               <groups>
                                               <group>

<name>Grupo</name>
                                               </group>
                               </grupos>
                </category>
</configdata>

Array
(
    [name] => Categoria
    [grupos] => Array
        (
            [grupo] => Array
                (
                    [name] => Grupo
                )
        )
)



Indeed, I woul like to generate something like this:

Array
(
    [name] => Categoria
    [grupos] => Array
        (
            [grupo] => Array
                (
                 [0] => Array
                        (
                            [name] => Grupo 1
                        )
                )
        )
)



Does anyone see how can we do that.



Regards



-- 
khyatti Reda
Tel: +21255880898

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux