Errror: INCORRECT NAMESPACE in Custom Sitemap Structure

227 Views Asked by At

I want to create custom site map for my site: https://adaway.info , the problem is that when I write the whole thing, it gives an error of Incorrect Namespaces on a number of lines.

Can anyone explain how to get rid of this?

(P.S: For my convenience I have used yoast sitemap for now, but I'm really looking for a custom sitemap.)

1

There are 1 best solutions below

0
On

You have to be extremely careful to ensure that the schema and locations are exactly as this:

http://www.sitemaps.org/schemas/sitemap/0.9 - I once had
http://www.sitemaps.org/schemas/sitemap/0.9
and it returned the same error that you are receiving. See if you can spot the trailing whitespace.

Here is an example using SimpleXML:

$xml = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><urlset></urlset>');
$xml->addAttribute('xmlns','http://www.sitemaps.org/schemas/sitemap/0.9');
$xml->addAttribute('xmlns:xmlns:xsi','http://www.w3.org/2001/XMLSchema-instance');
$xml->addAttribute('xmlns:xsi:schemaLocation', 'http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd');