Christian Spitschan: XML Änderung (Zugriff über Attribut)

Beitrag lesen

Hallo,
Ich möchte den Inhalt eines XML Elementes über PHP ändern.
In Worten: Ändere diesjenige Element meiner XML Datei, welches
als Attribut den Wert 'xy' besitzt.

<?php
include 'example.php';
$xml = simplexml_load_string($xmlstr);

foreach ($xml->movie[0]->rating as $rating) {
   switch((string) $rating['type']) {
   case 'thumbs':
       $rating = '10';
       break;
   case 'stars':
       $rating = '5';
       break;
   }
}
$xml->asXML('new.xml');
?>