SitemapWriter.php 874 Bytes
Newer Older
1 2 3 4
<?php

namespace Drupal\simple_sitemap\Plugin\simple_sitemap\SitemapGenerator;

5
use Drupal\Core\Url;
6 7 8 9 10

/**
 * Class SitemapWriter
 * @package Drupal\simple_sitemap\Plugin\simple_sitemap\SitemapGenerator
 */
11 12
class SitemapWriter extends \XMLWriter {

13
  const GENERATED_BY = 'Generated by the Simple XML Sitemap Drupal module: https://drupal.org/project/simple_sitemap.';
14 15 16
  const XML_VERSION = '1.0';
  const ENCODING = 'UTF-8';

17 18 19 20 21 22 23
  /**
   * Adds the XML stylesheet to the XML page.
   */
  public function writeXsl() {
    $xsl_url = Url::fromRoute('simple_sitemap.sitemap_xsl')->toString();
    $this->writePI('xml-stylesheet', 'type="text/xsl" href="' . $xsl_url . '"');
  }
24

25 26 27 28 29 30 31 32
  public function writeGeneratedBy() {
    $this->writeComment(self::GENERATED_BY);
  }

  public function startSitemapDocument() {
    $this->startDocument(self::XML_VERSION, self::ENCODING);
  }

33
}