/** * @covers ByJG\Util\XmlUtil::removeNode */ public function testRemoveNode() { $dom = XmlUtil::createXmlDocumentFromStr('<root><subject>Text</subject><a/><b/></root>'); $node = XmlUtil::selectSingleNode($dom->documentElement, 'subject'); XmlUtil::removeNode($node); $this->assertEquals(self::XMLHEADER . "\n" . '<root>' . '<a/>' . '<b/>' . '</root>' . "\n", $dom->saveXML()); }
/** * Remove a node specified by your tag name. You must pass a DOMDocument ($node->ownerDocument); * * @param DOMDocument $domdocument * @param string $tagname * @return bool */ public static function removeTagName($domdocument, $tagname) { $nodeLista = $domdocument->getElementsByTagName($tagname); if ($nodeLista->length > 0) { $node = $nodeLista->item(0); XmlUtil::removeNode($node); return true; } else { return false; } }