SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: RSS Gone Wrong

  1. #1
    SitePoint Addict
    Join Date
    Nov 2000
    Posts
    224
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    RSS Gone Wrong

    Hi all, I found this tutorial on how to setup an RSS Feed made all the necessary changes, saved it and I'm getting an error when I tried to validate it.

    This is the error

    Code:
    This feed does not validate.
    line 3, column 48: XML parsing error: <unknown>:3:48: syntax error [help]
    
    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
                                                    ^
    Suggesting that the last " before ; is wrong?

    This is the complete code, but the above was the only issue showing on the validator.

    Code:
    <?php
    header("Content-type: text/xml");
    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
    // Set RSS version.
    echo "
    <rss version=\"2.0\"> ";
    // Start the XML.
    echo "
    <channel>
    <title>This is the title</title>
    <description>Information to describe the overall content of this feed</description>
    <link>http://www.phatjoints.com/</link>";
    // Create a connection to your database.
    require("config.php");
    // Query database and select the last 10 entries.
    $data = mysql_query("SELECT * FROM rssnews ORDER BY id DESC LIMIT 10");
    while($row = mysql_fetch_array($data))
    {
    
    // Continue with the 10 items to be included in the <item> section of the XML.
    echo "
    <item>
    <link>http://www.phatjoints.com/rsstest.php?id=".$row[id]."</link>
    <guid isPermaLink=\"true\">http://www.phatjoints.com/rsstest.php?id=".$row[id]."</guid>
    <title>".$row[Title]."</title>
    <description><![CDATA[".$row[Content]."]]></description>
    <comments>http://www.phatjoints.com/rsstest.php?id=".$row[id]."#Comments</comments>
    </item>";
    }
    echo "
    </channel>
    </rss>";
    ?>
    I'm going through various tutorials from different sites and they don't always fit together to well as I am new to it.

    Thanks for any help

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,258
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)
    Is this an error with the XML or the PHP?
    Line 3 of your XML output is not line 3 of the PHP code.
    I think the problem may be due to the whitespace. Instead of
    PHP Code:
    echo "
    multiple
    lines
    of
    output"

    Try
    PHP Code:
    echo "multiple";
    echo 
    "lines";
    echo 
    "of";
    echo 
    "output"

  3. #3
    SitePoint Addict
    Join Date
    Nov 2000
    Posts
    224
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    not sure what you mean there?
    the w3c feed validation shows it as an 'XML parsing error'
    this link is the validation results LINK
    but i see what you mean about it being the php...ummm

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,258
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)
    It looks like you simply renamed a PHP file with the .xml extension (PHP code is not valid XML). If so, the PHP code will not get parsed unless you configure PHP to parse .xml files. Which probably isn't a good idea. Try giving the file the .php extension and validating it's XML output then.

  5. #5
    SitePoint Addict
    Join Date
    Nov 2000
    Posts
    224
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mittineague View Post
    It looks like you simply renamed a PHP file with the .xml extension (PHP code is not valid XML). If so, the PHP code will not get parsed unless you configure PHP to parse .xml files. Which probably isn't a good idea. Try giving the file the .php extension and validating it's XML output then.
    I hang my head in shame...yes the tutorial didn't say what to name it so went for the wrong one...validates fine now thank you

  6. #6
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,258
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)
    If you want the feed to have an .xml extension, maybe you could do an Apache mod-rewrite in your .htaccess file so that HTTP requests for feed.xml go to feed.php eg.
    Code:
    RewriteRule feed\.xml feed.php [L]
    But please be very careful. Messing with the .htaccess file is nothing to do carelessly. Making a simple mistake can bring down your site. So save a back-up copy, and make sure you understand the directive syntax and regex before you try changing it.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •