0

I want to remove the whole sticker node by calling the id 100. But nothing happens really. Any idea ?

$xml = new DOMDocument();
$xml->load('../write.xml');

    $result = $xpath->query('/stickers/sticker[id="100"]');
    $result->childNodes->item(0)->parentNode->removeChild($result->childNodes->item(0));

$xml->save('../write.xml');


      <stickers>
          <sticker> /* Remove */
            <text>Thaishi1</text>
            <id>100</id>
          </sticker>
            <sticker>
             </position>
            <text>Thaishi2</text>
            <id>200</id>
          </sticker>
        </stickers>
4

1 に答える 1

1

「何も起こらない」場合は、error_reporting を適切なデバッグ レベルに設定します->childNodes。プロパティがないという警告が表示されるはずです。

$result->item(0)->parentNode->removeChild($result->item(0));

これはうまくいくはずです。

于 2013-03-19T14:57:26.680 に答える