I'm using node.js and xml2js to create a xml sitemap.xml.
It looks all fine, but when I want to define the attributes e.g.:
'$': {
'xmlns': 'http://www.sitemaps.org/schemas/sitemap/0.9'
},
... like this:
var obj = {
'urlset': {
'$': {
'xmlns': 'http://www.sitemaps.org/schemas/sitemap/0.9'
},
'url': [
{
'loc': URL_DOMAIN,
'changefreq': 'monthly',
'priority': 1
},
{
'loc': URL_DOMAIN+'/data-privacy',
'changefreq': 'monthly',
'priority': 0.5
}
]
}
};
var builder = new xml2js.Builder({ xmldec: {'version': '1.0', 'encoding': 'UTF-8'} });
var xml = builder.buildObject(obj);
res.header('Content-Type','text/xml').send(xml)
... the atributes for the urlset won't render:
<urlset>
<url>
<loc>http://127.0.0.1:2000</loc>
<changefreq>monthly</changefreq>
<priority>1</priority>
</url>
<url>
<loc>http://127.0.0.1:2000/data-privacy</loc>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
</url>
... I would expect:
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
...
</url>
What am I missing?
... If I do a test:
'urlset': {
'$': {
'test': 'test'
},
... it works:
<urlset test="test">
...
</url>