You are here

public function XmlSitemapWriter::startDocument in XML sitemap 2.x

Same name and namespace in other branches
  1. 8 src/XmlSitemapWriter.php \Drupal\xmlsitemap\XmlSitemapWriter::startDocument()

Starts an XML document.

Parameters

string $version: The version number of the document.

string $encoding: The encoding of the document.

string $standalone: Yes or No.

Return value

bool Returns TRUE on success.

Throws

XmlSitemapGenerationException Throws exception when document cannot be started.

File

src/XmlSitemapWriter.php, line 109

Class

XmlSitemapWriter
Extended class for writing XML sitemap files.

Namespace

Drupal\xmlsitemap

Code

public function startDocument($version = '1.0', $encoding = 'UTF-8', $standalone = NULL) {
  $this
    ->setIndent(FALSE);
  $result = parent::startDocument($version, $encoding);
  if (!$result) {
    throw new XmlSitemapGenerationException("Unknown error occurred while writing to file {$this->uri}.");
  }
  if (\Drupal::config('xmlsitemap.settings')
    ->get('xsl')) {
    $this
      ->writeXsl();
  }
  $this
    ->startElement($this
    ->isIndex() ? 'sitemapindex' : 'urlset', TRUE);
  return $result;
}