Jump to content


Photo

**SOLVED** Stupid DOM is starting to drive me crazy...


  • Please log in to reply
No replies to this topic

#1 448191

448191
  • Staff Alumni
  • Advanced Member
  • 3,545 posts
  • LocationNetherlands

Posted 20 May 2006 - 11:33 AM

class simpleXML extends DOMDocument
{
    private $filePath;
    private $rootNode;
    
    function __construct($file)
    {
        parent::__construct();
        if(file_exists($file)){
            parent::load($file);
        }
            else {    //Create root element:
            $this->rootNode = parent::createElement(substr($file,strrpos($file,'/' )+1,strlen($file)));
            parent::appendChild($this->rootNode);
        }
        $this->filePath = $file;
        $this->preserveWhitespace = false;    
        $this->formatOutput = true;
    }
    function __destruct()
    {
        parent::save($this->filePath);        
    }    
    function putNodes(&$arr,$oldnode=false)
    {
        //First time through we need the rootNode object:
        if(!$oldnode) {
            $oldnode = $this->rootNode;
        }
        foreach($arr as $key => $value)
        {
            if(is_array($value)) {
                $newnode = parent::createElement($key);
                [b]$oldnode->appendChild($newnode);[/b]
                self::putNodes($value,$newnode);
            }
                else {
                $newnode = parent::createElement($key);
                $oldnode->appendChild($newnode);            
                $nodeValue = parent::createTextNode($value);
                $oldnode->appendChild($nodeValue);
            }
        }
    }
}

The problem is with the putNodes method. Somehow php claims that at some point, $oldnode isn't an object.. [img src=\"style_emoticons/[#EMO_DIR#]/huh.gif\" style=\"vertical-align:middle\" emoid=\":huh:\" border=\"0\" alt=\"huh.gif\" /]

Here:
if(is_array($value)) {
   $newnode = parent::createElement($key);
   $oldnode->appendChild($newnode);
   self::putNodes($value,$newnode);
}
[!--sizeo:5--][span style=\"font-size:18pt;line-height:100%\"][!--/sizeo--]EDIT:[!--sizec--][/span][!--/sizec--]
Nevermind, I spotted the problem, it's in the constructor.. [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users