Search code examples
phpxmlsimplexml

Save XML from SimpleXMLElement failed to open stream error


The XML file and the folder on the server where the file is kept are world read write in a Windows Vista, IIS 7 environment. Calling the asXML function returns this warning and the file isn't updated.

Warning: SimpleXMLElement::asXML(communities.xml) simpleelement.asxml failed to open stream: permission denied in c:\path\make_update.php.

The file make_update.php updates nodes in the XML.

<?php

ini_set('display_errors', 1);
error_reporting(E_ALL);

function make_update( $nodeid, $name, $top, $left, $width, $height ) {

$nodes = new SimpleXMLElement('communities.xml', null, true);

$returnArray = $nodes->xpath("//COMMUNITY[@ID='$nodeid']");  
$node = $returnArray[0]; 
$node->TOP = $top;

$nodes->asXML('communities.xml');

return $node->TOP;
}

echo make_update(trim($_REQUEST['nodeid']),trim($_REQUEST['name']),trim($_REQUEST['top']),trim($_REQUEST['left']),trim($_REQUEST['width']),trim($_REQUEST['height']));

?>

Solution

  • Had to set permission on the folder containing the XML file in addition to the file to be read write. Did so by owner, system, user, iisuser.