2
Bug # 32615: (Replacing and inserting Fragments)
4
<?php require_once('skipif.inc'); ?>
7
$dom = new DomDocument;
8
$frag = $dom->createDocumentFragment();
9
$frag->appendChild(new DOMElement('root'));
10
$dom->appendChild($frag);
11
$root = $dom->documentElement;
13
$frag->appendChild(new DOMElement('first'));
14
$root->appendChild($frag);
16
$frag->appendChild(new DOMElement('second'));
17
$root->appendChild($frag);
19
$node = $dom->createElement('newfirst');
20
$frag->appendChild($node);
21
$root->replaceChild($frag, $root->firstChild);
24
$frag = $dom->createDocumentFragment();
26
$frag->appendChild(new DOMElement('newsecond'));
27
$root->replaceChild($frag, $root->lastChild);
29
$node = $frag->appendChild(new DOMElement('fourth'));
30
$root->insertBefore($frag, NULL);
32
$frag->appendChild(new DOMElement('third'));
33
$node = $root->insertBefore($frag, $node);
35
$frag->appendChild(new DOMElement('start'));
36
$root->insertBefore($frag, $root->firstChild);
38
$frag->appendChild(new DOMElement('newthird'));
39
$root->replaceChild($frag, $node);
41
$frag->appendChild(new DOMElement('newfourth'));
42
$root->replaceChild($frag, $root->lastChild);
44
$frag->appendChild(new DOMElement('first'));
45
$root->replaceChild($frag, $root->firstChild->nextSibling);
47
$root->removeChild($root->firstChild);
49
echo $dom->saveXML()."\n";
51
while ($root->hasChildNodes()) {
52
$root->removeChild($root->firstChild);
55
$frag->appendChild(new DOMElement('first'));
56
$root->insertBefore($frag, $root->firstChild);
58
$node = $frag->appendChild(new DOMElement('fourth'));
59
$root->appendChild($frag);
61
$frag->appendChild(new DOMElement('second'));
62
$frag->appendChild(new DOMElement('third'));
63
$root->insertBefore($frag, $node);
65
echo $dom->saveXML()."\n";
67
$frag = $dom->createDocumentFragment();
68
$root = $dom->documentElement;
69
$root->replaceChild($frag, $root->firstChild);
77
<root><first/><newsecond/><newthird/><newfourth/></root>
80
<root><first/><second/><third/><fourth/></root>
83
<root><second/><third/><fourth/></root>