Define XML xmlsn, xsi, ... for Sitemap file.

S

Shapper

Hello,

I have the following C# code:

XDocument document = new XDocument(new XDeclaration("1.0", Encoding.UTF8.HeaderName, "yes"));

XElement urlset = new XElement(XNamespace.Get(@"http://www.w3.org/2001/XMLSchema-instance") + "urlset",
new XAttribute(XNamespace.Xmlns + "xsd", XNamespace.Get(@"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd")),
new XAttribute(XNamespace.Xmlns + "xsi", XNamespace.Get(@"http://www.w3.org/2001/XMLSchema-instance"))
);

document.Add(urlset);

Basically I am trying to get the following:

<?xml version='1.0' encoding='UTF-8'?>

<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"

xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"</urlset>

But I get the following:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<xsi:urlset xmlns:xsd="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<url>
<loc>/</loc>
<lastmod>2012-09-03T16:37Z</lastmod>
<changefreq>daily</changefreq>
<priority>1</priority>
</url>
<url>
<loc>/en/users/verify/1/a04a8c6d-5d3b-405b-adb0-447e3a419b80</loc>
<lastmod>2012-08-14T16:37Z</lastmod>
<changefreq>monthly</changefreq>
<priority>0.4</priority>
</url>
</xsi:urlset>

How can I solve this?

Thank You,

Miguel
 
A

Arne Vajhøj

Hello,

I have the following C# code:

XDocument document = new XDocument(new XDeclaration("1.0", Encoding.UTF8.HeaderName, "yes"));

XElement urlset = new XElement(XNamespace.Get(@"http://www.w3.org/2001/XMLSchema-instance") + "urlset",
new XAttribute(XNamespace.Xmlns + "xsd", XNamespace.Get(@"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd")),
new XAttribute(XNamespace.Xmlns + "xsi", XNamespace.Get(@"http://www.w3.org/2001/XMLSchema-instance"))
);

document.Add(urlset);

Basically I am trying to get the following:

<?xml version='1.0' encoding='UTF-8'?>

<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"

xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
</urlset>

But I get the following:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<xsi:urlset xmlns:xsd="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<url>
<loc>/</loc>
<lastmod>2012-09-03T16:37Z</lastmod>
<changefreq>daily</changefreq>
<priority>1</priority>
</url>
<url>
<loc>/en/users/verify/1/a04a8c6d-5d3b-405b-adb0-447e3a419b80</loc>
<lastmod>2012-08-14T16:37Z</lastmod>
<changefreq>monthly</changefreq>
<priority>0.4</priority>
</url>
</xsi:urlset>

How can I solve this?

I assume that the problem is urlset namespace not the url sub elements.

new
XElement(XNamespace.Get(@"http://www.w3.org/2001/XMLSchema-instance") +
"urlset",

->

new XElement("urlset",

should get rid of that.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top