public function toDOMElement($document = null)
 {
     if (!$document) {
         $document = new \DOMDocument();
     }
     // Builds and appends head to the HTML document
     $html = $document->createElement('html');
     if ($this->isRTLEnabled) {
         $html->setAttribute('dir', 'rtl');
     }
     $head = $document->createElement('head');
     $html->appendChild($head);
     $link = $document->createElement('link');
     $link->setAttribute('rel', 'canonical');
     $link->setAttribute('href', $this->canonicalURL);
     $head->appendChild($link);
     $charset = $document->createElement('meta');
     $charset->setAttribute('charset', $this->charset);
     $head->appendChild($charset);
     $this->addMetaProperty('op:markup_version', $this->markupVersion);
     if ($this->header && count($this->header->getAds()) > 0) {
         $this->addMetaProperty('fb:use_automatic_ad_placement', $this->isAutomaticAdPlaced ? 'true' : 'false');
     }
     if ($this->style) {
         $this->addMetaProperty('fb:article_style', $this->style);
     }
     // Adds all meta properties
     foreach ($this->metaProperties as $property_name => $property_content) {
         $head->appendChild($this->createMetaElement($document, $property_name, $property_content));
     }
     // Build and append body and article tags to the HTML document
     $body = $document->createElement('body');
     $article = $document->createElement('article');
     $body->appendChild($article);
     $html->appendChild($body);
     if ($this->header && $this->header->isValid()) {
         $article->appendChild($this->header->toDOMElement($document));
     }
     if ($this->children) {
         foreach ($this->children as $child) {
             if (Type::is($child, TextContainer::getClassName())) {
                 if (count($child->getTextChildren()) === 0) {
                     continue;
                 } elseif (count($child->getTextChildren()) === 1) {
                     if (Type::is($child->getTextChildren()[0], Type::STRING) && trim($child->getTextChildren()[0]) === '') {
                         continue;
                     }
                 }
             }
             $article->appendChild($child->toDOMElement($document));
         }
         if ($this->footer && $this->footer->isValid()) {
             $article->appendChild($this->footer->toDOMElement($document));
         }
     } else {
         $article->appendChild($document->createTextNode(''));
     }
     return $html;
 }
 public function getContextClass()
 {
     return TextContainer::getClassName();
 }
 /**
  * Implements the Container::getContainerChildren().
  *
  * @see Container::getContainerChildren().
  * @return array of TextContainer
  */
 public function getContainerChildren()
 {
     $children = array();
     foreach ($this->textChildren as $content) {
         // Recursive check on TextContainer, if something inside is valid, this is valid.
         if (Type::is($content, TextContainer::getClassName())) {
             $children[] = $content;
         }
     }
     return $children;
 }