views:

243

answers:

1

I have an xml file (Student.xml) like this

<student>
  <studentinfo>
   <name>
       <first>John</first> 
       <last>Doe</last>
   </name>
   <gender>male</gender>   
  </studentinfo>
</student>

and my php code

<?php

         $dom = new DOMDocument;

         $dom->load('Student.xml');

         $student = $dom->documentElement;

         $studentinfo = $student->getElementsByTagName('first')->item(0);

         $newName = $student->createTextNode('Jame'); 

         $student->replaceChild($newName, $student); 
?>

I can not replace my data inside, please help me to solve this problem?

A: 

In the last line in your php, shouldn't the second parameter be $studentinfo and not $student?

According to what I found at http://www.phpbuilder.com/manual/en/function.dom-domnode-replacechild.php, the second parameter is the node to replace and, according to your code, $studentinfo is the node to replace (from what I can see).

Michael Todd