Search code examples
xmlrss

Last build date in a rss xml


How to put the last build date in a rss xml? I have been searching, and for instance: https://validator.w3.org/feed/docs/rss2.html

I even copy-paste the exact same tag that w3.org gives as example, but the w3.org validator says: Undefined item element: lastBuildDate

<lastBuildDate>Sat, 07 Sep 2002 0:00:01 GMT</lastBuildDate>

https://validator.w3.org/feed/

w3 Schools gives a similar tag example. The validator gave me the same error:

<lastBuildDate>Thu, 27 Apr 2006</lastBuildDate>

https://www.w3schools.com/xml/rss_tag_lastbuilddate.asp


Solution

  • For me the validator says that your date is not valid RFC-822 date-time

    Add the missing zero for hours and it should be fine:

    <lastBuildDate>Sat, 07 Sep 2002 00:00:01 GMT</lastBuildDate>
    

    w3schools example also gives an invalid date format.

    EDIT:

    To have lastBuildDate (or any other tag that is not in the spec) under <item>, I believe it is only possible by using some namespace:

    <?xml version="1.0" encoding="UTF-8" ?>
    <rss version="2.0"
    xmlns:ownnamespace="http://www.foobar.com/ns/ownnamespace/">
    
    <channel>
      <title>W3Schools Home Page</title>
      <link>https://www.w3schools.com</link>
      <description>Free web building tutorials</description>
      <lastBuildDate>Sat, 07 Sep 2002 00:00:01 GMT</lastBuildDate>
      <item>
        <title>RSS Tutorial</title>
        <link>https://www.w3schools.com/xml/xml_rss.asp</link>
        <description>New RSS tutorial on W3Schools</description>
        <ownnamespace:lastBuildDate>Sat, 07 Sep 2002 00:00:01 GMT</ownnamespace:lastBuildDate>
      </item>
    </channel>
    
    </rss>
    

    This is valid but the validator complains about interoperability with feed readers when using an unknown namespace.