Jump to content

[SOLVED] RSS feed not validating correctly


dvdflashbacks

Recommended Posts

I can't seem to figure out how to make my RSS .xml file work.  I have tried handcoding this a few times now and it doesn't seem to validate properly.

 

Here is the link for it:

 

http://www.nothingaboutnothing.com/rss.xml

 

This is a dynamic blog type site, so I also can't seem to find an RSS app that will work, since most seem to only work with static html.

 

Any suggestions?

 

Thanks in advance.

Link to comment
Share on other sites

When I check the source of the page, I saw:

 

<?php header('Content-type:text/xml');?>
<rss version="2.0">
<channel>
<title>A BlogAboutNothing</title>
<link>http://www.nothingaboutnothing.com/</link>
<description>A BlogAboutNothing</description>
<lastBuildDate>Mon, 12 Sep 2005 18:37:00 GMT</lastBuildDate>
<language>en-us</language>

<?php require_once('Connections/conndb.php'); ?>

<?php
mysql_select_db($database_conndb, $conndb);
$query_Recordset1 = "SELECT blog_item_id, blog_item_datetime, blog_item_title, Left(blog_item, 150) as blog_item FROM blog_items ORDER BY blog_item_datetime DESC ";
$Recordset1 = mysql_query($query_Recordset1, $conndb) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);


while($result = mysql_fetch_array($Recordset1)){
?>

<item>
<title><?=htmlentities(strip_tags($result['blog_item_title'])); ?></title>
<description><?=htmlentities(strip_tags($result['blog_item'],'ENT_QUOTES')); ?></description>
<link>http://www.nothingaboutnothing.com/archive.php?id=<?=$result['blog_item_id']; ?></link>
<guid>http://www.nothingaboutnothing.com/archive.php?id=<?=$result['blog_item_id']; ?></guid>
<pubDate><?php echo date('r',$row_Recordset1['blog_item_datetime']); ?></pubDate>
</item>

<? } ?>

</channel>
</rss>

 

So therefore the PHP isn't executed because it's not a PHP file.  How are you creating the RSS feed?  You need to do all the stuff you did in that .xml file but in a PHP file and then output it to the XML file.

Link to comment
Share on other sites

You have a couple options...

 

1) Rename the file to .php and add this to the top:

header('Content-type: text/xml');

 

2) Tell Apache to send XML files through the PHP parser. To do that, create a .htaccess file in the same dir, and add this line to it:

AddType application/x-httpd-php .xml

 

3) Put that script in a separate file, and have it write the output to the XML file. Then, set that script to run on a scheduled job, or when items in the database are updated.

Link to comment
Share on other sites

Hi Darkwater,

 

Ok, I checked and that line is at the top of the file exactly as you typed it. 

 

If you go to the link it shows the file now, but it doesn't have one of my most recent entries listed.

 

I am not sure how these RSS are supposed to work, but I thought that it would update live after each entry that I add to the Blog.  And I am not sure how to actually syndicate it for other people to subscribe.

 

thanks. 

Link to comment
Share on other sites

I do not see how the query could not be working since it is pulling up everything but 1 record.  And this 1 record in fact displays on my actual site as the first record in the blog list (repeat region.)

 

Sorry, I am not sure.  I have never done RSS before.  I looked at the query again though, and it looks correct from what I can tell.  Very strange. 

 

Could it be the date at the top of the page.  The build date say Sept of 2005???

Link to comment
Share on other sites

Hey Guys,

 

Sorry to be a pain.

 

So I have double and triple checked this thing.  I can't see anything that is preventing this record from not displaying in the feed.  I also found no way to unsubscribe to this feed when I was testing it out.  So that is another weird problem.

 

I ran the file through a validator and it looks like my date formats are not validating, so I am not sure if that is part of the problem.

 

Any thoughts?

 

Thanks.

Link to comment
Share on other sites

Hey Rhodesa,

 

Sorry, I have been experimenting all day with this.  Here are the results so far:

 

This version displays all records except the most recent:

http://www.nothingaboutnothing.com/rss.php

 

And this version displays only the latest record over and over:

http://www.nothingaboutnothing.com/rss2.php

 

I am totally lost on this.

 

Link to comment
Share on other sites

Sorry, here they are.

 

rss.php

<?php header('Content-type:text/xml');?>
<?php require_once('Connections/conndb.php'); ?>
<?php

mysql_select_db($database_conndb, $conndb);
$query_Recordset1 = "SELECT blog_item_id, blog_item_datetime, blog_item_title, Left(blog_item, 250) as blog_item FROM blog_items ORDER BY blog_item_datetime DESC";
$Recordset1 = mysql_query($query_Recordset1, $conndb) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<rss version="0.92">
<channel>
<title>A BlogAboutNothing</title>
<link>http://www.nothingaboutnothing.com/</link>
<description>A BlogAboutNothing</description>
<language>en-us</language>

<?php 
while($result = mysql_fetch_array($Recordset1)){
?>

<item>
<title><?=htmlentities(strip_tags($result['blog_item_title'])); ?></title>
<description><?=htmlentities(strip_tags($result['blog_item'])); ?></description>
<link>http://www.nothingaboutnothing.com/archive.php?id=<?=$result['blog_item_id']; ?></link>
<guid>http://www.nothingaboutnothing.com/archive.php?id=<?=$result['blog_item_id']; ?></guid>
<pubDate><?=htmlentities(strip_tags($result['blog_item_datetime'])); ?></pubDate>
</item>

<? } ?>

</channel>
</rss>
<?php
mysql_free_result($Recordset1);
?>

 

And the second one:

 

rss2.php

<?php header('Content-type:text/xml');?>
<?php require_once('Connections/conndb.php'); ?>
<?php

mysql_select_db($database_conndb, $conndb);
$query_Recordset1 = "SELECT blog_item_id, blog_item_datetime, blog_item_title, Left(blog_item, 250) as blog_item FROM blog_items ORDER BY blog_item_datetime DESC";
$Recordset1 = mysql_query($query_Recordset1, $conndb) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<rss version="0.92">
<channel>
<title>A BlogAboutNothing</title>
<link>http://www.nothingaboutnothing.com/</link>
<description>A BlogAboutNothing</description>
<language>en-us</language>

<?php 
while($result = mysql_fetch_array($Recordset1)){
?>

<item>
<title><?php echo $row_Recordset1['blog_item_title']; ?></title>
<description><?php echo $row_Recordset1['blog_item']; ?></description>
<link>http://www.nothingaboutnothing.com/archive.php?id=<?=$result['blog_item_id']; ?></link>
<guid>http://www.nothingaboutnothing.com/archive.php?id=<?=$result['blog_item_id']; ?></guid>
<pubDate><?php echo $row_Recordset1['blog_item_datetime']; ?></pubDate>
</item>

<? } ?>

</channel>
</rss>
<?php
mysql_free_result($Recordset1);
?>

 

 

Link to comment
Share on other sites

ok...let me try to explain the mysql_* functions...

 

mysql_query() => Executes the SQL, and returns a pointer to a result set

mysql_fetch_assoc() => Returns a row from the result set, and advances the cursor forward

 

so, when you execute mysql_fetch_assoc() right after the query (but before the loop), you are basically throwing away a record. this is what the code should be:

<?php
  header('Content-type:text/xml');
  require_once('Connections/conndb.php');

  mysql_select_db($database_conndb, $conndb);
  $sql = "SELECT blog_item_id, blog_item_datetime, blog_item_title, Left(blog_item, 250) as blog_item FROM blog_items ORDER BY blog_item_datetime DESC";
  $result = mysql_query($sql, $conndb) or die(mysql_error());
?>
<rss version="0.92">
<channel>
<title>A BlogAboutNothing</title>
<link>http://www.nothingaboutnothing.com/</link>
<description>A BlogAboutNothing</description>
<language>en-us</language>

<?php 
while($row = mysql_fetch_assoc($result)){
?>

<item>
  <title><?=htmlspecialchars(strip_tags($row['blog_item_title'])); ?></title>
  <description><?=htmlspecialchars(strip_tags($row['blog_item'])); ?></description>
  <link>http://www.nothingaboutnothing.com/archive.php?id=<?=$row['blog_item_id']; ?></link>
  <guid>http://www.nothingaboutnothing.com/archive.php?id=<?=$row['blog_item_id']; ?></guid>
  <pubDate><?=htmlspecialchars(strip_tags($row['blog_item_datetime'])); ?></pubDate>
</item>

<? } ?>

</channel>
</rss>

Link to comment
Share on other sites

Hi Rhodesa,

 

Thanks for this info.  Unfortunately, it is the same result, well actually it says that the page has errors on it. ???

 

Here is the code that I entered just so you can compare and make sure I didn't type anything wrong (I tried doing a copy paste, but my code editor didn't seem to grab things right from the clip board.)

 

<?php
  header('Content-type:text/xml');
  require_once('Connections/conndb.php');

  mysql_select_db($database_conndb, $conndb);
  $sql = "SELECT blog_item_id, blog_item_datetime, blog_item_title, Left(blog_item, 250) as blog_item FROM blog_items ORDER BY blog_item_datetime DESC";
  $result = mysql_query($sql, $conndb) or die(mysql_error());
?>
<rss version="0.92">
<channel>
<title>A BlogAboutNothing</title>
<link>http://www.nothingaboutnothing.com/</link>
<description>A BlogAboutNothing</description>
<language>en-us</language>

<?php 
while($row = mysql_fetch_assoc($result)){
?>

<item>
  <title><?=htmlspecialchars(strip_tags($row['blog_item_title'])); ?></title>
  <description><?=htmlspecialchars(strip_tags($row['blog_item'])); ?></description>
  <link>http://www.nothingaboutnothing.com/archive.php?id=<?=$row['blog_item_id']; ?></link>
  <guid>http://www.nothingaboutnothing.com/archive.php?id=<?=$row['blog_item_id']; ?></guid>
  <pubDate><?=htmlspecialchars(strip_tags($row['blog_item_datetime'])); ?></pubDate>
</item>

<? } ?>

</channel>
</rss>

Link to comment
Share on other sites

Just sent you the file. Also got two weird errors when I tried to validate using a feed validator online.

This feed does not validate.

line 1, column 0: Undefined root element: br [help]

<br />line 2, column 0: XML parsing error: <unknown>:2:0: junk after document element [help]

<b>Parse error</b>:  syntax error, unexpected ':' in <b>/home/dvdflas1/publi ...In addition, interoperability with the widest range of feed readers could be improved by implementing the following recommendation.

Feeds should not be served with the "text/html" media type [help]

 

Thanks.

Link to comment
Share on other sites

Big thanks to Rhodesa for fixing this problem for me.  Here is the final output which now works for anyone that runs into anything similar:

 

<?php
  /**
   * Use FULL php tags, not the short <? as some PHP
   * installs may not be configured to use them
   * 
   * In the header() function, it had MSWord style quotes
   * around it. I changed them to normal quotes
   *
   * Requires should come at the beginning
   */
  require_once('Connections/conndb.php');
?>
<rss version="0.92">
<channel>
<title>A BlogAboutNothing</title>
<link>http://www.nothingaboutnothing.com/</link>
<description>A BlogAboutNothing</description>
<language>en-us</language>
<?php
  mysql_select_db($database_conndb, $conndb) or die(mysql_error());
  $sql = "SELECT blog_item_id, blog_item_datetime, blog_item_title, Left(blog_item, 250) as blog_item FROM blog_items ORDER BY blog_item_datetime DESC";
  $result = mysql_query($sql, $conndb) or die(mysql_error());

  /**
   * The WHILE loop was missing here...i added it back
   */
  while($row = mysql_fetch_array($result)){
?>
<item>
  <title><?=htmlspecialchars(strip_tags($row['blog_item_title'])); ?></title>
  <description><?=htmlspecialchars(strip_tags($row['blog_item'])); ?></description>
  <link>http://www.nothingaboutnothing.com/archive.php?id=<?=$row['blog_item_id']; ?></link>
  <guid>http://www.nothingaboutnothing.com/archive.php?id=<?=$row['blog_item_id']; ?></guid>
  <pubDate><?=htmlspecialchars(strip_tags($row['blog_item_datetime'])); ?></pubDate>
</item>

<?php
}
?>
</channel>
</rss>

 

The two changes that I had to make on Rhodesa revised file is that I had to remove the header line (all of my other research indicates that this line is needed for the RSS feed to work properly if it is not an xml file) and I also had to rename the file to something other than rss.php.  I believe these two inconsistencies are configurational issues or bugs with my hosting company.  But I don't really know.

 

But it now works correctly!  Thanks also to everyone who gave feedback on this. 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.