So using SimpleXML in PHP is possibly one of the worst hells of typecasting and data extraction procedures one can encounter, or close to it 🙂 But more the point, you don’t need to walk down that road alone, enter JSON.
In the simplest of ways, this will typically get you something useful:
$pvar = json_decode ($xml);
(Where $xml is a SimpleXML-type object) This returns a “slightly easier to manage” PHP array.
If you want an associative array, do this:
$pvar = json_decode ($xml, true);
To get it back to JSON, you simply use:
$json = json_encode ($pvar).
You may need to handle XML data, but you don’t necessarily need to work with it in XML form inside your application. The above examples may not work fully for you if you have to deal with “foreign” files or clean the input data prior to conversion, but you get the idea.
This is, obviously, obvious to many. It’s a lifesaver for others 🙂
It seems like Lenovo (and most likely others) have their own Volkswagen Gate to deal with. I don’t know if this warning has been on all their sleeves or if this is a recent addition. Perhaps the US State of California has threatened to sue them. Regardless, I’d like Lenovo to inform their customers about what’s going on … ?
Warning: This product contains chemicals known to the State of California to cause cancer and birth defects or other reproductive harm. Manufactured for Lenovo 2015-06-05. ThinkPad 12″ fitted reversible sleeve (P/N: 4X40E48909).