Is there an easy way to marshal a PHP associative array to and from XML? For example, if I have the following array:
$items = array("1", "2",
array(
"item3.1" => "3.1",
"item3.2" => "3.2"
"isawesome" => true
)
);
How would I turn it into something similar to the following XML in as few lines as possible, then back again:
<items>
<item>1</item>
<item>2</item>
<item>
<item3_1>3.1</item3_1>
<item3_2>3.2</item3_2>
<isawesome>true</isawesome>
</item>
</items>
I don't really care if I have to change the array structure a bit or if the XML that comes out is different to the above example. I've been trying to work with PHP's XMLReader and XMLWriter, but the documentation is so poor and the code I've produced as a consequence looks nothing like what I feel it should look like:
$xml = SomeXMLWriter::writeArrayToXml($items);
$array = SomeXMLWriter::writeXmlToArray($xml);
Does it really have to be any harder than that to get a basic, raw XML dump of a PHP array without writing my own custom class?
@cruizer, I try to avoid PEAR. In addition to the configuration headaches I've had with it, I've never stuck with any of the packages I've ever used from it.
@Oddmund & Jared Can you please provide some examples of using SimpleXML to do what I am trying to do?