Beispiel #1
0
 /**
  * Replace this node
  *
  * @param $string
  *
  * @return $this
  */
 protected function replaceNode($string)
 {
     if (empty($string)) {
         $this->node->parentNode->removeChild($this->node);
         return null;
     }
     $newDocument = new HtmlDomParser($string);
     if ($this->normalizeStringForComparision($newDocument->outerText()) != $this->normalizeStringForComparision($string)) {
         throw new RuntimeException('Not valid HTML fragment');
     }
     $newDocument = $this->cleanHtmlWrapper($newDocument);
     $newNode = $this->node->ownerDocument->importNode($newDocument->getDocument()->documentElement, true);
     $this->node->parentNode->replaceChild($newNode, $this->node);
     $this->node = $newNode;
     return $this;
 }