1
votes

CakePHP doc says I can transform an array to XML using XML::build(). All I get are errors. Here's my post to the #cakephp irc.

i have a multi-dimension data set, for which I made a wrapper function to output my xml. It errors out with this message. What am I doing wrong?

1
As suggested, I changed the call to $xml = Xml::build(array('root' => $_records));. Now I get the error: Warning (2): SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 3: parser error : Extra content at the end of the document [CORE\Cake\Utility\Xml.php, line 177] String could not be parsed as XML - Mike S.
Adding a return element removed the warning $xml = Xml::build(array('return' => 'simplexml', 'root' => $_records));. Error has been replaced with Invalid input. - Mike S.
After stepping through the app, I found where the app bombs. bin.cakephp.org/view/403624274. The problem is I don't know why or how to fix it. - Mike S.
Ok, here's another attempt. bin.cakephp.org/view/724808941. The output looks wrong, which would explain the errors. But it doesn't explain why the array is encoded incorrectly. - Mike S.
I've since learned that the array's root element is numeric and the parent and child elements are actually constructed as child siblings of that root. Definitely not what I want. I'm creating the array like this: $invoices = $this->Invoice->find('all');. Nothing special, but it's giving me fits trying to understand why this is happening and how to fix it. - Mike S.

1 Answers

0
votes

Here is a class I found that traverses multi-dimensional php arrays and converts to xml.

Convert PHP Array to XML or Simple XML Object if you wish