PHP5 and XML
April 23rd, 2006
One of the best things in PHP5 is that almost everything regarding XML was rewritten; All XML extensions are now based on the libxml2 library, from Zend article:
In addition to the better-known SAX support inherited from PHP 4, PHP 5 supports DOM according to the W3C standard and XSLT with the very fast libxslt engine. It also incorporates the new PHP-specific SimpleXML extension and a much improved, standards-compliant SOAP extension. Given the increasing importance of XML, the PHP developers decided to enable more XML support by default. This means that you now get SAX, DOM and SimpleXML enabled out of the box, which ensures that they will be installed on many more servers in the future. XSLT and SOAP support, however, still need to be explicitly configured into a PHP build.
The SimpleXML is an amazing easy object to handle XML data, it’s still new, so don’t expect it to be complete, but it certainly is a godsend.
XML in PHP 5 - What’s New?
PHP Manual: DOM Functions
Array to XML function for PHP
SimpleXML example:
<select id=”reports_categories” name=”reports_categories”> <option value=”">[Please Select]</option> <?php $xml = simplexml_load_file(’reports.xml’); foreach($xml->category as $category) { echo ‘<option value=”‘ . $category[’name’] . ‘”>’ . $category[’text’] . ‘</option>’; }; unset($xml); ?> </select>
The XML:
<reports> <category name=”booked_jobs” text=”Booked Jobs”> <report name=”job_date” text=”By Job Date”> <screenshot>booked_job_date.gif</screenshot> <transform>reports_xsl/booked_job_date.xsl</transform> <description> View your jobs by a range of dates </description> </report> <report name=”book_date” text=”By Book Date”> <transform>reports_xsl/booked_book_date.xsl</transform> <description> View your jobs by a range of dates </description> </report> <report name=”closed_date” text=”By Closed Date”> <transform>reports_xsl/booked_close_date.xsl</transform> <description> View your jobs by a range of dates </description> </report> </category> </reports>

One comment on “PHP5 and XML”
01
thank you very much for your example.It is very help for my learning stage.keep it up.
Thanks
Dhanush.R