有没有办法使用Zend Framework和PHP将XML转换为数组?我见过人们使用SimpleXML来做这件事,但我想知道是否有通过Zend Framework的方法.
示例XML,我想转换为数组将是:
<library>
<book>
<authorFirst>Mark</authorFirst>
<authorLast>Twain</authorLast>
<title>The Innocents Abroad</title>
</book>
<book>
<authorFirst>Charles</authorFirst>
<authorLast>Dickens</authorLast>
<title>Oliver Twist</title>
</book>
</library>
转换后的数组将如下所示:
Array
(
[0] => Array (
[authorFirst] => Mark
[authorLast] => Twain
[title] => Innocents Abroad
)
[1] => Array (
[authorFirst] => Charles
[authorLast] => Dickens
[title] => Oliver Twist
)
)
解决方法:
如果你看看Zend_Config_XML的source code,你会看到他们使用SimpleXML来做几乎就是这样.我猜?他们建议你这样做.