Jump to content

**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\" /]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.