ksmatthews Posted January 22, 2008 Share Posted January 22, 2008 HI All, I am having some trouble changing an XML document with the floowing code: // create XML object using XML file as parameter $xmlobj = simplexml_load_file($folder . $XML_filename); if($xmlobj == false) { $flag = false; $message = "Error: XML file cannot be loaded"; } // access and modify elements $xmlobj->sipLines->line->displayName = $dir_num; $xmlobj->sipLines->line->featureLabel = $dir_num; $xmlobj->sipLines->line->authName = $dir_num; $xmlobj->sipLines->line->authPassword = $dir_num; echo $xmlobj->asXML(); When I execute 'echo $xmlobj->asXML();' the changes have NOT been done. The path $xmlobj->sipLines->line->displayName is correct and variable $dir_num is populated Any ideas ? regards, Steven Matthews Quote Link to comment https://forums.phpfreaks.com/topic/87242-using-simplexml/ Share on other sites More sharing options...
ziv Posted January 22, 2008 Share Posted January 22, 2008 I tried to do the same thing, and here are the results: <?xml version="1.0" encoding="UTF-8"?> <root> <x> <y>aaa</y> </x> <x> <y>bbb</y> </x> </root>'; <?php $xml = simplexml_load_file('the file above...'); echo "start: {$xml->x->y}", PHP_EOL; $xml->x->y = 'ccc'; echo "end: {$xml->x->y}", PHP_EOL; echo $xml->asXML(); ?> results: start: aaa end: ccc <?xml version="1.0" encoding="UTF-8"?> <root> <x> <y>ccc</y> </x> <x> <y>bbb</y> </x> </root> it seems to work fine, maybe, if we you'll attach the XML file, i could assist you.... Quote Link to comment https://forums.phpfreaks.com/topic/87242-using-simplexml/#findComment-446286 Share on other sites More sharing options...
ksmatthews Posted January 23, 2008 Author Share Posted January 23, 2008 HI Ziv, Thanks for that. Here is the XML file, attached, regards, Steven M [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/87242-using-simplexml/#findComment-446762 Share on other sites More sharing options...
Barand Posted January 23, 2008 Share Posted January 23, 2008 should be $xmlobj->sipProfile->sipLines->line->displayName etc Quote Link to comment https://forums.phpfreaks.com/topic/87242-using-simplexml/#findComment-446792 Share on other sites More sharing options...
ksmatthews Posted January 23, 2008 Author Share Posted January 23, 2008 Thanks again, I am employing your suggestions but the original input file remains the same (ie has not changed) I am using a linux file sytem. After running the script, when I look at the last modified time, it remains the same ... Has a new output file been created, if so where ? One last thing, what does $xmlobj->asXML(); actually do ? regards, Steven M Quote Link to comment https://forums.phpfreaks.com/topic/87242-using-simplexml/#findComment-446933 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.