summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndres Rey <[email protected]>2016-11-14 16:42:12 +0000
committerAndres Rey <[email protected]>2016-11-14 16:42:12 +0000
commit4ff745766c127ecfa013c8344fd1c1e2f4a2dc5d (patch)
tree29a6ee5acf613e926abac5cee00cb02982149ad9 /src
parent34460727a82e8d11775d9a137e7f5f07dc302f45 (diff)
Fixed setNodeTag
Diffstat (limited to 'src')
-rw-r--r--src/Readability.php16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/Readability.php b/src/Readability.php
index 2e2bf01..0ad22e4 100644
--- a/src/Readability.php
+++ b/src/Readability.php
@@ -268,13 +268,25 @@ class Readability extends Element implements ReadabilityInterface
}
/**
- * Sets the node name.
+ * Changes the node tag name. Since tagName on DOMElement is a read only value, this must be done creating a new
+ * element with the new tag name and importing it to the main DOMDocument
*
* @param string $value
*/
public function setNodeTag($value)
{
- $this->node->nodeName = $value;
+ $new = new \DOMDocument();
+ $new->appendChild($new->createElement($value));
+
+ $childs = $this->node->childNodes;
+ for ($i = 0; $i < count($childs); $i++) {
+ $import = $new->importNode($childs->item($i), true);
+ $new->firstChild->appendChild($import);
+ }
+
+ // The import must be done on the firstChild of $new, since $new is a DOMDocument and not a DOMElement.
+ $import = $this->node->ownerDocument->importNode($new->firstChild, true);
+ $this->node->parentNode->replaceChild($import, $this->node);
}
/**