448191 Posted May 20, 2006 Share Posted May 20, 2006 [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\" /] Quote Link to comment https://forums.phpfreaks.com/topic/10057-solved-stupid-dom-is-starting-to-drive-me-crazy/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.