public function Twig_Node::toXml

File

drupal/core/vendor/twig/twig/lib/Twig/Node.php, line 73

Class

Twig_Node
Represents a node in the AST.

Code

public function toXml($asDom = false) {
  $dom = new DOMDocument('1.0', 'UTF-8');
  $dom->formatOutput = true;
  $dom
    ->appendChild($xml = $dom
    ->createElement('twig'));
  $xml
    ->appendChild($node = $dom
    ->createElement('node'));
  $node
    ->setAttribute('class', get_class($this));
  foreach ($this->attributes as $name => $value) {
    $node
      ->appendChild($attribute = $dom
      ->createElement('attribute'));
    $attribute
      ->setAttribute('name', $name);
    $attribute
      ->appendChild($dom
      ->createTextNode($value));
  }
  foreach ($this->nodes as $name => $n) {
    if (null === $n) {
      continue;
    }
    $child = $n
      ->toXml(true)
      ->getElementsByTagName('node')
      ->item(0);
    $child = $dom
      ->importNode($child, true);
    $child
      ->setAttribute('name', $name);
    $node
      ->appendChild($child);
  }
  return $asDom ? $dom : $dom
    ->saveXml();
}