XML : replace the xml element with php

I want the peter element replace to other element I Input It.I try to use replace()but it not work.I don't know my code is that right or wrong. I hope have someone to fix my problem.Thx

This is the XML code:

  <?xml version="1.0" encoding="UTF-8"?>  <document>     <information>      <name>peter</name>  </information>  </document>    

This is the PHP code:

  <html>      <head>      </head>      <body>          <form action="index.php" method="POST">                              Name:<input type="text" name="name"/><br/>               <input type="submit" name="ok" value="add" /><br>              <input type="submit" name="check" formaction="read.php" value="check the date" />                        </form>                <?php           if(isset($_POST['ok'])){    $xml= new DomDocument("1.0","UTF-8");    $xml->load("write.xml");      $rootTag=$xml->getElementsByTagName("document")->item(0);    $dataTag=$xml->createElement("information");      $NameTag= $xml->createElement("name",$_POST['name']);      $dataTag->appendChild($NameTag);     $rootTag->appendChild($dataTag);      $dataTag->replaceChild($NameTag,$NameTag);        $xml->formatOutput = true;    $string_value=$xml->saveXML();    $xml->save("write.xml");          }    ?>   </body>  </html>    

No comments:

Post a Comment