Read/Write An XML File Using CakePHP 1.3
Here’s a snippet that is sure to be quite useful for PHP programmers and web developers who often work with XML files. It’s a code to read/write an XML file by using CakePHP. Some of you might find a few lines a bit familiar, which is because parts of it are borrowed from the concept of parsing XML.
//Save data to an xml App::import('Helper', 'Xml'); App::import('Core','File'); $xml = new XmlHelper(); $file = $xml->header(); $file .= $xml->serialize($config, array('whitespace' => true)); $xmlFile = new File(path_to_file); $xmlFile->write($file, 'w'); $xmlFile->close(); //Read data from an XML if (file_exists(path_to_file)) { App::import('Helper', 'Xml'); $parsed_xml = new XML(path_to_file); $data = $parsed_xml->toArray(); $this->data['Email'] = $data['StdClass']; }
2 Comments
Jleagle
09.10.2012
1.3 is pretty old now.
dogmatic69
09.11.2012
When using Cake 1.3 and SimpleXml is available on your server its recommended to use that instead.
The Xml classes are know to be quite buggy and there is a bit of a performance gain in using SimpleXml
Since 2.x Cake wraps SimpleXml and DomDocument as its no longer targeted at php4
Read/Write An XML File Using CakePHP 1.3 | Blogfreakz | CakePHP Articles
09.10.2012
[...] 10th September 2012 Keith@Blogfreakz · CakePHP, Tutorials · 0 Comments [...]
There are no trackbacks to display at this time.