XML sitemap syntax for canonical pages



I'm using PHP and XML DOM to dynamically add new children to my sitemap as new web pages are created. The code uses XML DOM and addchild(); to update the file.


I am developing my mobile compatible version of the site and want bots to see canonical pages correctly.


Google for example recommends this format (From google-webmaster dev) :



<url>
<loc>http://ift.tt/1pBxQVN;
<xhtml:link
rel="alternate"
media="only screen and (max-width: 640px)"
href="http://ift.tt/U4ZjVe" />
</url>


The tag



<xhtml:link BuNcH oF StUfFD HeRe />


doesn't look right to me? How is this a properly formatted XML child element?


Is the syntax below an acceptable alternative?:



<url>
<loc>http://ift.tt/1pBxQVN;
<xhtml:link>
rel="alternate"
media="only screen and (max-width: 640px)"
href="http://ift.tt/U4ZjVe"
</xhtml:link>
</url>


Why this is a problem to me is the way I'm developing my sitemap in XML DOM. As far as I know you can only add properly formatted children in XML. Here is my PHP I use to generate my sitemap:



$dom = new DOMDocument;
$dom->preserveWhiteSpace = FALSE;
$imagechild = 'image:image';
$imageloc = 'image:loc';
$xml=simplexml_load_file("../sitemap.xml");
$map = $xml->addChild('url');
$map->addChild('loc', "http://mywebsite/".$page_pathloc);
$img = $map->addChild($imagechild, '', 'http://ift.tt/Sqn21o');
$img->addChild($imageloc, $img_link);
$dom->formatOutput = TRUE;
$xml->saveXML('../sitemap.xml');

No comments:

Post a Comment