- var_dump: documentation ( source)
- json_decode: documentation ( source)
- json_encode: documentation ( source)
<?php
$xml = <<<XML
<?xml version="1.0" encoding="utf-8"?>
<touhou xmlns:windows="http://example.com/windows" xmlns:alt="http://example.com/alt">
<!-- included in json -->
<game>
<title lang="en">Highly Responsive to Prayers</title>
<title lang="jp">東方靈異伝</title>
</game>
<game>
<title lang="en">Story of Eastern Wonderland</title>
<!-- the romaji attribute won't be included in json -->
<title lang="jp" alt:romaji="Tōhō Fūmaroku">東方封魔録</title>
</game>
<!-- won't be included in json -->
<windows:game>
<title lang="en">Embodiment of Scarlet Devil</title>
<title lang="jp">東方紅魔郷</title>
</windows:game>
<windows:game>
<title lang="en">Perfect Cherry Blossom</title>
<title lang="jp">東方妖々夢</title>
</windows:game>
</touhou>
XML;
$result = json_decode(json_encode(new SimpleXMLElement($xml)), true);
var_dump($result);