PHP Tutorials - Using XML
After the hype, the Extensible Markup Language (XML) is now really used almost everywhere. An application that receives a lot of buzz is Web Services, a technology that is covered in detail in Communicating with Others. However, XML can be used elsewhere, as well. It is a good format to store any kind of data.
The tasks behind using XML are always the same: reading data from XML and writing data into it. So this tutorial focuses on these tasks and shows how to implement them.
Unfortunately, PHP 4's XML support was somewhat limited. Some extensions did not prove to be very stable. This changed drastically with PHP 5 and a revamped XML support. Therefore, the main focus of this tutorial is on PHP 4. In PHP 5.1, some new features will be added that are already covered in this tutorial.
As the sample XML file and format in this tutorial, the XML from the following code reuses the quotes database example from the previous tutorial. As you can see,
<quotes> is the root element, and each quote (including its author and the year the coding was coined) is contained in a
The sample XML file (quotes.xml; excerpt)
<?xml version="1.0" encoding="ISO-8859-1" ?>
<coding>Hasta la vista, baby!</coding>
Table of content (tutorial index)