From The Blog

PHP: parsing all the XML including CDATA

22 October 2012, in

It is common when writing XML files to put data like HTML and XML in CDATA to avoid mixing between XML tags and content tags

but whatever comes inside CDATA is ignored, and not parsed

so to read which inside it when parsing XML add the attribute "LIBXML_NOCDATA" like this:

$xml = simplexml_load_file('xmlfile', NULL, LIBXML_NOCDATA);


Post a Comment

Using Yahoo Weather API to get weather conditions in CakePHP2

2 June 2012, in

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

// your XML file's location

/*w is the code of the city, and u is the unit of temperature (c/f)
$xml = Xml::build('http://weather.yahooapis.com/forecastrss?w=615702&u=c');

$xml should contain the following data, where you can extract whatever you want from it



Post a Comment

Parsing XML easily in CakePHP 2

2 June 2012, in

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



Post a Comment