Created
March 21, 2012 17:21
-
-
Save devster/2149765 to your computer and use it in GitHub Desktop.
Helper sitemap index xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* SiteMapIndexXML | |
* | |
* A simple helper to make simple sitemap.xml of index | |
* | |
* Usage: | |
* $sitemap = new SiteMapIndexXML(); | |
* $sitemap->addSiteMap('http://example.org/sitemap-products.xml'); | |
* $sitemap->saveXML() // returns the string xml | |
* | |
* @author Jeremy Perret <[email protected]> | |
*/ | |
class SiteMapIndexXML extends \DOMDocument | |
{ | |
public $root; | |
public function __construct($charset = 'UTF-8') | |
{ | |
parent::__construct('1.0', $charset); | |
$this->root = $this->appendChild($this->createElement('sitemapindex')); | |
$xmlns = $this->createAttribute('xmlns'); | |
$xmlns->value = 'http://www.sitemaps.org/schemas/sitemap/0.9'; | |
$this->root->appendChild($xmlns); | |
} | |
public function addSiteMap($url) | |
{ | |
$urlNode = $this->createElement('sitemap'); | |
$this->root->appendChild($urlNode); | |
$urlNode->appendChild($this->_createTextNode('loc', $url)); | |
} | |
protected function _createTextNode($name, $value) | |
{ | |
$el = $this->createElement($name); | |
$el->appendChild($this->createTextNode($value)); | |
return $el; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment