
DOMDocumentFragment::append 메소드는 지정된 노드를 문서의 맨 마지막에 추가합니다.
만약 특정 노드를 문서의 맨 마지막에 추가하고 싶다면, append 메소드를 사용하여 노드를 추가하면 됩니다.
예를 들어, 다음과 같이 사용할 수 있습니다.
#hostingforum.kr
php
$doc = new DOMDocument();
$fragment = $doc->createDocumentFragment();
$node = $doc->createElement('div');
$fragment->appendChild($node);
$doc->appendChild($fragment);
위의 예제에서, $fragment->appendChild($node); 문장에서 노드가 문서의 맨 마지막에 추가됩니다.
만약 특정 노드를 문서의 특정 위치에 추가하고 싶다면, insertBefore 메소드를 사용할 수 있습니다.
#hostingforum.kr
php
$doc = new DOMDocument();
$fragment = $doc->createDocumentFragment();
$node = $doc->createElement('div');
$child = $doc->createElement('p');
$doc->appendChild($child);
$fragment->appendChild($node);
$doc->documentElement->appendChild($fragment);
위의 예제에서, $doc->documentElement->appendChild($fragment); 문장에서 노드가 문서의 맨 마지막에 추가됩니다.
만약 특정 노드를 문서의 특정 위치에 추가하고 싶다면, insertBefore 메소드를 사용할 수 있습니다.
#hostingforum.kr
php
$doc = new DOMDocument();
$fragment = $doc->createDocumentFragment();
$node = $doc->createElement('div');
$child = $doc->createElement('p');
$doc->appendChild($child);
$fragment->appendChild($node);
$doc->documentElement->insertBefore($fragment, $child);
위의 예제에서, $doc->documentElement->insertBefore($fragment, $child); 문장에서 노드가 문서의 특정 위치에 추가됩니다.
이러한 예제를 통해, DOMDocumentFragment::append 메소드를 사용하여 노드를 추가하고, 노드의 위치를 지정하는 방법을 알 수 있습니다.
2025-07-26 23:30