views:

184

answers:

1

Hi,

I am trying to write a XML file with Zend_Config_Writer_Xml. I found out a problem that I can't write multiple items under a root. I would like to do,

<root>
   <item name="test"></item>
   <item name="test2"></item>
</root>

I can't find a method to do this on zend documentation.

Please advise me.

+1  A: 

Standard writer doesn't do exactly that, but it works like this: if you do:

$config = new Zend_Config(array(), true);
$config->root = array("test1" => 1, "test2" => array(1,2));
$writer = new Zend_Config_Writer_Xml();
$writer->write('config.xml', $config);

then what you get is:

<zend-config xmlns:zf="http://framework.zend.com/xml/zend-config-xml/1.0/"&gt;
  <root>
    <test1>1</test1>
    <test2>1</test2>
    <test2>2</test2>
  </root>
</zend-config>

I don't think standard writer does attributes, you'd need to override it for that.

StasM