$d->appendChild($t3 = $xml->createTextNode(" t3 ")); $d->appendChild($b = $xml->createElement("b")); $b->appendChild($xml->createElement("X")); $d->appendChild($t4 = $xml->createTextNode(" t4 ")); $d->appendChild($xml->createTextNode(" xxx ")); echo "\ndiv:\n"; print_node_r($d); echo "\nInsert t4 before t3:\n"; $ret = $d->insertBefore($t4, $t3); print_node_r($d); echo "\n"; $frag = $xml->createDocumentFragment(); $t5 = $frag->appendChild($xml->createTextNode(" t5 ")); $frag->appendChild($i = $xml->createElement("i")); $i->appendChild($xml->createTextNode(" frob ")); $frag->appendChild($xml->createTextNOde(" t6 ")); echo "\np:\n"; print_node_r($p); echo "\nFragment:\n"; print_node_r($frag); echo "\nAppending fragment to p:\n"; $p->appendChild($frag); print_node_r($p); echo "\nFragment:\n"; print_node_r($frag); echo "\ndiv:\n"; print_node_r($d); echo "\nInserting fragment before t4\n"; $d->insertBefore($frag, $t4); print_node_r($d); echo "\np:\n";