Add new child at the end of the children.
public appendChild ( |
||
$nodes | The appended child | |
리턴 |
public function findNextNodeByText(DiDomElement $element, $expression, $grep = false) { $childNodes = $element->getNode()->childNodes; $length = $childNodes->length; $stop = false; for ($i = 0; $i < $length; $i++) { $node = $childNodes->item($i); if ($stop && trim($node->textContent)) { $document = new DiDomDocument(); $document->appendChild($node); return $document; } else { if (!$grep && $expression == $node->textContent) { $stop = true; } else { if ($grep && preg_match($expression, $node->textContent)) { $stop = true; } } } } }
/** * Get the DOM document with the current element. * * @param string $encoding The document encoding * * @return \DiDom\Document */ public function toDocument($encoding = 'UTF-8') { $document = new Document(null, false, $encoding); $document->appendChild($this->node); return $document; }
/** * Get the DOM document with the current element. * * @return \DiDom\Document */ public function toDocument() { $document = new Document(); $document->appendChild($this->domElement); return $document; }
public function testAppendChildException() { $this->setExpectedException('InvalidArgumentException'); $document = new Document('', true); $document->appendChild(null); }
/** * @expectedException InvalidArgumentException */ public function testAppendChildWithInvalidArgument() { $document = new Document(''); $document->appendChild(null); }
public function testAppendChild() { $html = '<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> </body> </html>'; $document = new Document($html); $this->assertCount(0, $document->find('span')); $node = $document->createElement('span'); $document->appendChild($node); $this->assertCount(1, $document->find('span')); $nodes = []; $nodes[] = $document->createElement('span'); $nodes[] = $document->createElement('span'); $document->appendChild($nodes); $this->assertCount(3, $document->find('span')); }