From The Blog

Parsing XML easily in CakePHP 2

2 June 2012, in CakePHP

It is very easy to parse XML in CakePHP , here is an example in CakePHP v2

// import XML Utility class
App::uses('Xml', 'Utility');

// your XML file's location
$xml1 = Xml::build('http://url-of-XML');

$xml2 = Xml::build('http://http://url-of-XML', array('return' => 'simplexml'));
// $xml now is a instance of SimpleXMLElement

// New method using DOMDocument
$xml3 = Xml::build('http://url-of-XML', array('return' => 'domdocument'));

// see the returned array
debug($xml1);
debug($xml2);
debug($xml3);



Post a Comment