Sitemap LastMod property serialized in an incorrect format
See original GitHub issueGoogle’s webmasters tools is throwing several errors on the LastMod property, “An invalid date was found. Please fix the date or formatting before resubmitting”. Upon inspection, as per sitemaps.org, the date must be in a W3C format.
I believe a minor update in SitemapNode.cs such as the following should do the trick (PS: not tested):
/// <summary>
/// Shows the date the URL was last modified, value is optional.
/// </summary>
[XmlElement("lastmod", Order = 2)]
public string LastModificationDateW3C
{
get
{
if (this.LastModificationDate != null)
{
return XmlConvert.ToString((DateTime)this.LastModificationDate);
}
return null;
}
}
/// <summary>
/// The date the URL was last modified
/// </summary>
public DateTime? LastModificationDate { get; set; }
Issue Analytics
- State:
- Created 7 years ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
Why is the sitemap validator returning an error for ...
According to the spec for lastmod , specifying the seconds isn't required for datetimes. The lastmod element uses the "W3C Datetime format", ...
Read more >How to serialize google sitemap in c# using XmlSerializer
You need to use the right namespace: [XmlRoot("urlset", Namespace = "http://www.sitemaps.org/schemas/sitemap/0.9")].
Read more >The Importance of Setting the "lastmod" Tag in Your Sitemap
The most prevalent issue with incorrectly set "lastmod" values in XML sitemaps is that they are identical, as in the example provided.
Read more >@astrojs/sitemap Astro Documentation
The serialize function should return SitemapItem , touched or not. The example below shows the ability to add sitemap specific properties individually.
Read more >Sitemap update error with date format
Hi! I'm trying to update my site's sitemap.xml and constantly receiving an error message about date format. I had the same date format ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The first method (converting to UTC) does not work, however the second method works perfectly! 😃
Just a recap, after retrieving the datetime required, I created a new DateTime, as per your second suggestion, like so:
Thanks for your support and for your awesome tool! 😃
You’re welcome.
It seems like there is a ToLocalTime method as well and it looks cleaner.