frankx: SimpleXML-Element löschen - $element und/oder $element[0]

Beitrag lesen

Hellihello Matthias,

try this:

<?php

error_reporting(E_ALL | E_STRICT);
header('Content-Type: text/plain');

$xmlstr = '<colors>
    <color>
       <name>Orange</name>
       <ton1>Rot</ton1>
       <ton2>Gelb</ton2>
    </color>
    <color>
       <name>Braun</name>
       <ton1>Rot</ton1>
       <ton2>Gruen</ton2>
    </color>
</colors>';

$xml = new SimpleXMLElement($xmlstr);

foreach($xml->xpath('color') as $color){
if ($color->ton1 == 'Rot') {
  unset($color[0]);
}
}

echo($xml->asXML());

?>

  
Warum funktioniert das? echo $color->asXML() funktioniert bei mir genauso wie echo $color[0]->asXML(). demnach funktioniert $color ja wie ein zwitter aus objekt und array.  
  
  
Dank und Gruß,  
  
[frankx](http://community.de.selfhtml.org/visitenkarten/view.php?key=82)

-- 
[tryin to](http://sauer-ernst.de) [multitain](http://multitain.de)  - Globus = Planet != Welt