DOMIT! v 0.1 Tutorial
<<    index    >>
1    2    3    4    5    6    7    8    9    10    11    12    13    14    15   
16    17    18    19    20    21    22    23    24    25    26   
replaceChild

If, instead of getting rid of your new cd, you decided to trade it with a friend for one that you liked better, you can use the replaceChild method to substitute one node for another.

The replaceChild method takes two parameters - the old node and the new node:


//build new node
$tradedCD =& $cdCollection->createElement("cd");
$tradedCD->attributes["id"] = 4;
$nameNode =& $cdCollection->createElement("name");
$titleNode =& $cdCollection->createElement("title");
$tradedCD->appendChild($nameNode);
$tradedCD->appendChild($titleNode);
$nameNode->appendChild($cdCollection->createTextNode("John Scofield"));
$titleNode->appendChild($cdCollection->createTextNode("Uberjam"));

//perform replacement
$cdLibrary =& $cdCollection->documentElement;
$cdLibrary->replaceChild($cdLibrary->lastChild, $tradedCD);

The replaceChild method returns a reference to the new node.


Documentation generated by ClassyDoc, using the DOMIT! and SAXY parsers.
Please visit Engage Interactive to download free copies.