![]() |
RSS Parsing with SimpleXML
2 Attachment(s)
This tutorial will provide a simple example of one method for parsing an XML document, more specifically, an RSS formatted XML document. This tutorial will use the new Simple XML object added to PHP 5.
If you wish to follow this tutorial properly then you should first download the RSS XML document attached to this thread called talkphp.xml. Now you’ve done that, create a new file on your website and add the following code: PHP Code:
That’s all there is to using SimpleXML, easy, huh? |
You can't beat SimpleXML! Can you?
|
That looks awesome :O
|
SimpleXML is php5 right?
Nice example on how to use it :) |
Hmm. I'm sure that SimpleXML was available for PHP4 as an external module, but in PHP5 it became native to PHP5.
|
I just love how simple (pardon the pun) SimpleXML is to use. When comparing it to the nasty old days of parsing manually through an XML document, using SimpleXML is almost child's play.
PHP Code:
children() line above is just to access a namespaced node (dc:creator) -- it's nothing scary. The LIBXML_NOCDATA flag will likely be the subject of an article/post here sooner or later. |
But what does your xml file look like?
Dont you need to install an rss reader to be able to use it as an rss feed? I have never really understood that bit, still learning XML but struggling with how exactly you set your php file to decipher the xml file. and about 100 other really irritating questions. I am trying to work out how to create navigation menu with xml at the moment but in asp, it's fine if you use one of the bullcrap built in controls but what about making your own! lazy microsoft.. lazy |
Hi Avangelist.
If you take a look at the attachments for the main post you'll see one file called 'talkphp.xml'. This is the file that the code uses. So if you look inside that and then take another look at the code, possibly even run it on your local machine if you can, then I'm sure things will become a little clearer :) As for your second question, no, you do not need an RSS reader to read a RSS feed, the above code does just that, reads as RSS formatted XML file. |
PHP5 does it for you
Wow, that response was almost as slow as BT!
PHP5 has the incredibly simple XMLParser global which is a swizz to use so now I have no problems doing anything with XML files. What would be good is how to write to file with one so that you can easily update the file with new data. |
| All times are GMT. The time now is 08:22 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0