I am trying to make a video sitemap for video website. But I am facing a XMLExecption "The ':' character, hexadecimal value 0x3A, cannot be included in a name." This is because of colons (video:video) in the name.
XNamespace gs = "http://www.sitemaps.org/schemas/sitemap/0.9";
XDocument doc = new XDocument(
new XElement(gs + "urlset",
(from p in db.Videos
orderby p.video_id descending
select new XElement(gs + "url",
new XElement(gs + "loc", "http://www.example.com/video/" + p.video_id + "-" + p.video_query),
new XElement(gs + "video:video",
new XElement(gs + "video:thumbnail_loc", "http://cdn.example.com/thumb/" + p.video_image)
))).Take(50)));
doc.Save(@"C:\video_sitemap.xml");
Please tell me how to add colons in the name to generate dynamic xml sitemap using LINQ to SQL.
Thanks and Regards.
UPDATE:
This Video XML sitemap should look like on the page: Google Video Sitemap
video
here is the alias for a namespace. As per the example:
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
<url>
<loc>http://www.example.com/videos/some_video_landing_page.html</loc>
<video:video>
...
</video:video>
</url>
</urlset>
So you just need two XNamespace
values - one for the sitemap namespace and one for the video namespace:
XNamespace siteMapNs = "http://www.sitemaps.org/schemas/sitemap/0.9";
XNamespace videoNs = "http://www.google.com/schemas/sitemap-video/1.1";
XDocument doc = new XDocument(
new XElement(siteMapNs + "urlset",
(from p in db.Videos
orderby p.video_id descending
select new XElement(siteMapNs + "url",
new XElement(siteMapNs + "loc",
"http://www.example.com/video/" + p.video_id + "-" + p.video_query),
new XElement(videoNs + "video",
new XElement(videoNs + "thumbnail_loc",
"http://cdn.example.com/thumb/" + p.video_image)
)
)
).Take(50)
)
);
EDIT: If you really want this to use an alias of video
for the namespace, you can declare it in your root element:
XDocument doc = new XDocument(
new XElement(siteMapNs + "urlset",
new XAttribute(XNamespace.Xmlns + "video", videoNs),
(from p in db.Videos
...
See more on this question at Stackoverflow