Re[5]: [PHP] Object assignment

From: Date: Fri, 11 Jul 2003 02:00:06 +0000
Subject: Re[5]: [PHP] Object assignment
References: 1 2 3 4 5 6  Groups: php.general 
Request: Send a blank email to php-general+get-154820@lists.php.net to get a copy of this message
Hi, Did some more tweaking and if we create a new element for each node ther is no need to clone, saves a few lines of code :) function parseBranch($branch, &$doc, &$parent) { foreach ($branch as $key => $val) { switch ($key) { // parent attributes case ('ATTRIBUTES'): foreach ($val as $attrName => $attrVal) { switch ($attrName){ case 'VALUE': $nodeValue = $doc->create_text_node($attrVal); $parentValue = $parent->append_child($nodeValue); break; default: $parent->set_attribute($attrName, $attrVal); break; } } break; // parent value case ('VALUE'): $nodeValue = $doc->create_text_node($val); $parentValue = $parent->append_child($nodeValue); break; default: // parse children of this node foreach ($val as $children) { //create node $node = $doc->create_element($key); $child = $parent->append_child($node); //set is elements parseBranch($children, $doc, $child); } break; } } } -- regards, Tom

« previous php.general (#154820) next »