In previous posts (RSS Feed Breakage and RSS Feed Breakage: Update) some of you might have noticed how my RSS feeds were buggered up and not working or giving validation errors. I have finally found the solution for my issue!
It seems I needed to tell the XML parser to IGNORE whatever is in my description tags for each element of my feed. How did I go about finding this solution? Well I’ve always been envious of those who use WordPress as their blogging software because of how nicely formatted their RSS Feeds were and that they were usually complete as well. Since I have been interested in the past to write plug-ins for WordPress I have a copy of the code on my development server. This allowed me to look through the scripts and find the information I needed.
So I found my answer within the file: wp-rss2.php
I have seen the use of it before in perhaps one other tutorial on PHPFreaks.com but it never explained what exactly CDATA did nor why I would use it. So I didn’t!
Now if I really looked into XML a bit more I would of learnt what CDATA does and that is what I would need to get everything to work properly. Before I had to parse out the various HTML Entities that were making my RSS Feed’s invalid and I kept them to a certain length (partial feed) so that I had a better chance of not running into any odd characters.
The other thing that I noticed I do differently than anyone else is the way they handle the output of the information. In my script I actually write to a stand-alone .XML file on my server whereas WordPress and other people seem to use PHP to create the file on the fly using the header() function so that the script will output the XML file without having to read to a server. My way requires that the file has the proper permission on it for read access, which can be a security issue unless it is handled properly. WordPress and other RSS creation scripts would be the ideal way to go about it. You don’t need to worry about chmod issues or if the file is somehow corrupt; it just outputs the proper header for whatever program needs to read it.
Now I am happy that I have a Full, Validated, Formatted RSS Feed! Next I will try and tackle the highlighting of PHP/HTML code when I want to do code snippets within my posts!