hi all,
I have requirement to replace <name>name</name> with <name>username</name> in xml file,how can achieve this through php coding please help me.i m using following code but its not working
hi all,
I have requirement to replace <name>name</name> with <name>username</name> in xml file,how can achieve this through php coding please help me.i m using following code but its not working
Certainly; PHP has quite a few XML extensions. Personally, I find [man]DOM[/man] is usually the most convenient.
For more help, please attach the code and describe just how it's not working (and what it would do if it were working).
this is the php code i m using
$overfile="C:/xampp/htdocs/project/templates/user$template/templateDetails.xml";
//$xmlDoc = new DOMDocument();
$xmlDoc=simplexml_load_file("$overfile");
echo'XML file loaded';
foreach($xmlDoc as $install){
if($install->name=="$template"){
$install->name="user$template";
}
}
$xmlDoc->asXML($overfile);
and XML FILE is as follows
<install version="1.5" type="template" method="upgrade">
<name>template1</name>
</install>
I want to replace<name>template1</name> with <name>usertemplate1</name>
how can i do this
Well, you didn't say how it's not working (and in future you might like to use some of the markup tags described in the faq), but what you have looks overly complicated for what it's supposed to do. Can't you just write
$overfile="C:/xampp/htdocs/project/templates/user$template/templateDetails.xml";
$xmlDoc=simplexml_load_file($overfile);
echo'XML file loaded';
$xmlDoc->name = "user$template";
$xmlDoc->asXML($overfile);
Thank you very much its working