Sebastian: Frage zu DOM-XML

Beitrag lesen

Hallo!

Ich habe eine XML-Struktur, die ungefähr so aussieht:

<locations>
  <location a="1" b="2">
    <title>Lokation 1</title>
    <irgendeinTag>abc</irgendeinTag>
    <subRegions sr_a="0" sr_b="1" sr_c="0" />
  </location>
</locations>

gehe ich mit

$locations = $xpath->query( "//location" );

foreach( $locations as $location ) { }

die einzelnen Locations durch. Die Variable $subregion enthält einen beliebigen String (z.B. sr_a oder sr_y).

Nun will ich, dass mit DOM-XML der komplette <location>-Node gelöscht wird, wenn entweder

a) das Attribut mit dem Namen, der in $subregion gespeichert ist, im <subRegions>-Node nicht vorhanden ist
  b) oder dieses Attribut den Wert 0 hat.

Wie mache ich das möglichst einfach?

Liebe Grüße
Sebastian