You are here

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

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

Writes full element tag including support for nested elements.

Parameters

string $name: The element name.

string|array $content: The element contents or an array of the elements' sub-elements.

File

src/XmlSitemapWriter.php, line 195

Class

XmlSitemapWriter
Extended class for writing XML sitemap files.

Namespace

Drupal\xmlsitemap

Code

public function writeElement($name, $content = NULL) {
  if (is_array($content)) {
    $this
      ->startElement($name);
    $this
      ->writeRaw($this
      ->formatXmlElements($content));
    $this
      ->endElement();
  }
  else {
    parent::writeElement($name, Html::escape(static::toString($content)));
  }
  $this
    ->writeRaw(PHP_EOL);

  // After a certain number of elements have been added, flush the buffer
  // to the output file.
  $this->sitemapElementCount++;
  if ($this->sitemapElementCount % $this->linkCountFlush == 0) {
    $this
      ->flush();
  }
}