Question: How do you resolve the error that comes when generating an XML SiteMap? I would like to concate the element with a semicolon as a separator.
Here is the error "XmlException: The ':' character, hexadecimal value 0x3A, cannot be included in a name."
I am following the tutorial from developer.google.com on the link below
https://developers.google.com/search/docs/advanced/sitemaps/video-sitemaps#xml-namespace
Any help will be appreciated.
Login to See the Rest of the Answer
Answer: This error shows you that you cannot explicitly use a semicolon symbol in the XML Element Node. To solve this issue check out the code below:
XNamespace xmlns = "http://www.sitemaps.org/schemas/sitemap/0.9";
XElement root = null;// new XElement(xmlns + "urlset");
root = new XElement(xmlns + "urlset", new XAttribute("video", "http://www.google.com/schemas/sitemap-video/1.1")
XElement urlElement = new XElement(
xmlns + "url",
new XElement(xmlns + "loc", Uri.EscapeUriString(sitemapNode.Url)),
//Results
<url>
<loc>https://www.ernestech.com/video/details/2073/A-second-operation-started-on-this-context-before-a-previous-operation-completed</loc>
<video:video xmlns:video="http://www.sitemaps.org/schemas/sitemap/0.9">
<video:thumbnail_loc>https://www.ernestech.com/videos/DBContextInvalidOperation/DBContextInvalidOperation.png</video:thumbnail_loc>
<video:title>A second operation started on this context before a previous operation completed</video:title>
<video:description>In this video I will demonstrate how to solve the error that says, InvalidOperationException: A second operation started on this context before a previous operation completed. This is usually caused by different threads using the same instance of DbContext, however instance members are not guaranteed to be thread safe. This could also be caused by a nested query being evaluated on the client, if this is the case rewrite the query avoiding nested invocations.</video:description>
<video:content_loc>https://www.ernestech.com/videos/DBContextInvalidOperation/DBContextInvalidOperation.mp4</video:content_loc>
<video:view_count>693</video:view_count>
<video:rating>5</video:rating>
<video:requires_subscription>no</video:requires_subscription>
<video:family_friendly>yes</video:family_friendly>
</video:video>
</url>
References:
https://www.rssboard.org/media-rss