Hi all,

I'm trying to implement custom session handling and have decided to use files and xml. When setting variables I get a strange behaviour from SimpleXMLElement, however: it seems to duplicate the root node and place it within the original root node.

Here's the code which sets the variables:

PHP Code:
private function _setFile($name$value) {
    
$_this =& Session::getInstance();        
    
Cleaner::html($value);
    
Cleaner::html($name);
    
$xml = new SimpleXMLElement(Filesystem::readFile($_this->file));
    if(
file_exists(INCL_PATH DS $_this->file)) {
        if(
count($xml->xpath("/session/$name")) > 0) {
            
$xml->session->$name $value;
        } else {
            
$sesh $xml->xpath("/session");
            
$sesh[0]->addChild($name$value);
        }
        
Filesystem::writeFile($_this->file$xml->asXML(), true);
        
$_this->_addData($name$value);
        return 
true;
    } else {
        return 
false;
    }

The XML I get written to the session file is as follows:

Code:
<?xml version="1.0"?>
<session expires="1271013868" path="/">
<hello>moto</hello>
<session><hello>moto</hello></session>
</session>
(I added the line separations for readability)

I can't work out why this is happening but I'm fairly sure the extra <session> node is created here:

PHP Code:
} else {
    
$sesh $xml->xpath("/session");
    
$sesh[0]->addChild($name$value);

I don't really know why it's being populated though. Before any variables are set the xml document just contains the xml header and the root session node.

Any help would be much appreciated.