Jump to content

Archived

This topic is now archived and is closed to further replies.

448191

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

Recommended Posts

[code]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);
            }
        }
    }
}[/code]

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:
[code]if(is_array($value)) {
   $newnode = parent::createElement($key);
   $oldnode->appendChild($newnode);
   self::putNodes($value,$newnode);
}[/code]
[!--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\" /]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.