Welcome Guest, Not a member yet? Register   Sign In
Validating a RSS feed
#1

[eluser]Xeoncross[/eluser]
I want to validate an rss feed that a user enters and then I fetch and store. I know that SimpleXML only likes proper XML documents - but I don't think that it is enough to rely on it for my checking. I know that a document is supposed to have 3 elements (title, link, description) and then a bunch of < item > elements with the actual news rows.

So should I waste time using PHP to iterate over the whole object SimpleXML returns checking for these values - or is there a better way?

RSS
#2

[eluser]elvix[/eluser]
SimplePie is a php RSS parser (been ported to CI around here somewhere, I believe) that will probably do what you want much easier than SimpleXML.
#3

[eluser]Xeoncross[/eluser]
[quote author="elvix" date="1234600341"]SimplePie is a php RSS parser (been ported to CI around here somewhere, I believe) that will probably do what you want much easier than SimpleXML.[/quote]

Thanks for the suggestion. I am aware of simplepie but I wanted a lightweight solution that wouldn't takes a lot of memory and time to run like simplepie.


Also, I don't think you can beat simplexml in "easiness" ;-)

Code:
$rss_object = simplexml_load_string($file);
#4

[eluser]pistolPete[/eluser]
You could run feedvalidator.org locally, it's written in python:
http://feedvalidator.org/docs/howto/inst...d_run.html
#5

[eluser]Xeoncross[/eluser]
Ya, I thought about doing that - but it is +1MB in size! The goal I am looking for is finding a lightweight fast way to check the XML.
#6

[eluser]Xeoncross[/eluser]
Actually, I just found that rather than using SimpleXML I can use DomDocument to create / read XML files and streams. When I first started using XML PHP 4 was all there was and so the XML stuff scared me away -but the PHP 5 Dom functions are very easy to use.

Anyway, DomDocument has a validate function if anyone is interested. I don't know if it works or not - but I plan on testing it to see what I can come up with.

Code:
&lt;?php
$dom = new DOMDocument;
$dom->Load('book.xml');
if ($dom->validate()) {
    echo "This document is valid!\n";
}
?&gt;

Quote:When validating documents with this method there are two issues I don't like about it. First, it creates a bunch of warnings, which one would not expect, as the plot of calling this method is preventing any warnings that could occur when erroneously relying on the document's validity. Second, it only returns a boolean with no chance of getting additional details about the reasons for rendering invalid. - http://us2.php.net/manual/en/domdocument.validate.php

So no-one here has ever tried to validate a RSS feed or other XML source?




Theme © iAndrew 2016 - Forum software by © MyBB