Tutorials

Handling XML data

by Daniel Egeberg on May 26, 2008 7:22:44 AM

Introduction

This tutorial was originally posted on the old site on 20th December, 2007.

XML, Extensible Markup Language, is a general-purpose markup language which can be used for storing arbitrary data in a structured way. It is often used for sharing data between applications and a common usage of XML is for instance RSS feeds.

With the emerge of PHP 5, support for handling XML data has greatly improved and in this tutorial we will take a look at the features in PHP 5 which we can use to parse, alter and create XML documents. At the end of the tutorial we will also take a look at how you can create an RSS feed without writing a single line of XML and then we will make it into a reusable class which you can implement in your own applications. Additionally we'll create a really simple RSS reader.

Basic knowledge of XML is a prerequisite for this tutorial. Knowledge of XPath would be a good idea as it will be used a bit in this tutorial, however, this is not entirely important. Furthermore, OOP knowledge is a requirement as well.

Right, let's go to the next page and get started...

Comments

Great tutorial. Just so happens I was looking for something like this. Can't wait to see more tutorials.

1. super3boy on May 26, 2008 12:26:38 PM

Awesome tutorial, helped me a lot, thanks!

2. dezkit on May 26, 2008 10:03:42 PM

In part Parsing data of unknown structure is better to use SPL SimpleXMLIterator (http://www.php.net/~helly/php/ext/spl/classSimpleXMLIterator.html.

3. Ladislav Prskavec on May 27, 2008 11:04:40 AM

Excellent Tutorial Daniel. One question:
For the RSS Feed class, do I need any thing special for it to work. When I use it, it takes me to the Add to Google Reader or Add to Google Homepage option page. I chose to add to homepage, then it actually displays a box, but inside the box, it says:
"Information is temporarily unavailable." Is there anything missing from that tutorial or am I missing something simple? Any help woudl be appreciated.

4. cdn on Aug 14, 2008 2:03:45 PM

thanks for the good tutorial!!!!!!!!!!!!!

5. Oyeme on Oct 6, 2008 3:43:58 PM

Great tutorial!

Google came up with result just when I was in dire need to parse my xml data and show it on browser.

This tutorial was like a god-send to me.

6. Ankit Mathur on Dec 30, 2008 3:09:09 PM
Login or register to post a comment.