xml文件

<?xml version="1.0" encoding="utf-8"?>
<root>

<php100 id="2">
  <index>test test</index>
</php100>
<php100 id="3">
  <index>new xml content</index>
</php100>

</root>

php文件

<?php

 $doc = new DOMDocument();
 $doc->load( 'index.XML' );

 $root = $doc -> documentElement;

 $books = $doc->getElementsByTagName_r( "php100" );

 foreach( $books as $book ){
  if($book->getAttribute('id')==2){
  echo $book->getAttribute('id')."-";
  echo $book->getElementsByTagName_r( "index" )->item(0)->nodeValue='test test';
  echo "<br>";
  }

  if($book->getAttribute('id')==1){
  $root->removeChild($book);
    }
  }

  $doc->save('index.XML');

?>