& The MG\'s');
$year->setData('1962');
Those are the easy ones. It is toughest to deal with the tracks node. We need to
add multiple track nodes to this node, each of which needs to include the track
length as a parameter:
$track =& $tracks->addChild('track', array('length' => '1.45'));
$track->setData('Green Onions');
The second parameter that we pass to the addChild() method is an associative array
of node parameters. In this case we specify the length of the track as 1.45. We then
proceed to set the name of the track using the setData() method.
There is another way in which we could have added the length parameter to the
track node. The addAttribute() method is used to add and modify attributes.
Imagine we accidentally entered the wrong length value and we want to correct it:
$track->addAttribute('length', '2.45');
Saving
The last thing that we look at is how to save XML. Imagine we have parsed an
existing XML file and we have made some alterations to the parsed XML. In order
to apply these changes we need to convert the parsed document back into an XML
string and save it to the original file.
Pages:
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388