0

Hi Im trying to create a news feed using php. I have a php code written which connects to the database and retrieves information which is converted into XML. The file is however a .php and when I try to parse it using google reader it dosen't work because it only reads files which are XML. Here's my code:

<?php
header("Content-type: text/xml");
$dept = $_GET['dept'];
require_once ("/var/www/html/http/sass/includes/config.inc.php");
require_once ("sass_news.php");
$sassNews = paginate('sass_news', 'sass_news', $numResults, $offset, $order, $condition);
if($sassNews) {
    $xml_output = "<?xml version=\"1.0\"?>\n";
    $xml_output .= "<entries>\n";

        foreach($sassNews as $newsDetail){
        $xml_output .= "\t<entry>\n";
        $xml_output .= "\t\t<date>" . $newsDetail->news_start_date . "</date>\n";
        $xml_output .= "\t\t<text>" . $newsDetail->news_body_en . "</text>\n";
        $xml_output .= "\t</entry>\n";
     }

    $xml_output .= "</entries>";

    echo $xml_output;

}
?>
2
  • You can probably set the file extension as XML and still have the web server execute the PHP code. What web server are you using? Commented Jul 15, 2011 at 19:54
  • If you are writing XML by bashing together strings, you are probably generating invalid XML. Use an XML library to build XML, and validate Commented Jul 15, 2011 at 19:58

2 Answers 2

1

Try header('Content-disposition: attachment; filename=somename.xml'); at the top of the script. However, if Google Reader is going to allow only URLS which literally end in .xml, then you'll need to reconfigure your server to treat .xml files as PHP scripts and rename this script to whatever.xml.

Sign up to request clarification or add additional context in comments.

Comments

1

Have you read the RSS specification, that doesn't look like valid markup to me. It should have an rss node, a channel node and lots of other goodies. Also your content-type should be application/rss+xml

1 Comment

To check your feed you can use the Feed validation service: validator.w3.org/feed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.