-- Vadim Gabriel <[email protected]> wrote
(on Friday, 24 April 2009, 06:25 PM +0300):
> I was wondering if anyone willing to give some feedback about the proposal i
> made @link http://framework.zend.com/wiki/display/ZFPROP/
> Zend_Xml+-+Vadim+Gabriel
>
> I am not sure how often this is used by other developers but i use this very
> often. I am also not sure if this is something that was already made or talked
> about, I couldn't find anything about it.
You may want to see how Zend_Config_Xml and Zend_Config_Writer_Xml work,
as they already do much of this. As an example:
$xml =<<<EOX
<?xml version="1.0"?>
<foo>
<bar>Bar</bar>
<baz>
<foo>Foo</foo>
<bar>Bar</bar>
</baz>
</foo>
EOX;
$config = new Zend_Config_Xml($xml);
$arr = $config->toArray();
echo var_export($arr, 1), "\n";
$writer = new Zend_Config_Writer_Xml();
$writer->setFilename('php://stdout')
->setConfig($config);
ob_start();
$writer->write();
$genXml = ob_get_clean();
echo var_export($genXml, 1), "\n";
It's not flawless, but if you run the above, you'll see that the first
instance transforms the XML to an array, the second transforms a config
to XML. (You can transform an array to a config object by simply doing
$config = new Zend_Config($array); ) It may be useful to add a method to
the Zend_Config_Writer base class to allow retrieving the generated text
(instead of writing it directly to file) -- this would obviate the need
to do the output buffering hack above.
Otherwise, it kinda makes sense -- casting a SimpleXML object to an
array is non-recursive, and there are no native PHP libraries for
casting an array to an XML document. However, if what you want to do can
be accomplished with the config objects already, I'm not sure how much
need there is for an extra component.
--
Matthew Weier O'Phinney
Project Lead | [email protected]
Zend Framework | http://framework.zend.com/