/** * @group AppKit */ public function testXml2Array() { $xml = <<<EOT <?xml version="1.0" encoding="utf-8"?> <root> <param name="DING1">DONG</param> <param name="DING2"> DONG </param> <param name="DING3">DONG</param> <param name="DING4"> <param name="DING4.1"> <![CDATA[ LA OLA! ]]> </param> <param name="DING4.2">DONG</param> </param> </root> EOT; $dom = new DOMDocument('1.0', 'utf-8'); $dom->loadXML($xml); $root = $dom->getElementsByTagName('root'); AppKitArrayUtil::xml2Array($root, $dump); $this->assertCount(1, $dump); $this->assertCount(4, $dump['root']); $this->assertEquals('DONG', $dump['root']['DING4']['DING4.2']); }
/** * Creates a cronk array structure based on xml * @param string $xml * @return array */ private function xml2array($xml) { $dom = new DOMDocument('1.0', 'UTF-8'); $dom->loadXML($xml); $root = $dom->documentElement; $out = array(); AppKitArrayUtil::xml2Array($root->childNodes, $out); return $out; }