Re: Object assignment

From: Date: Wed, 09 Jul 2003 01:15:05 +0000
Subject: Re: Object assignment
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-154464@lists.php.net to get a copy of this message
Hi, Wednesday, July 9, 2003, 10:38:22 AM, you wrote: MG> I'm having trouble creating objects with DOMXML. As I loop through a level MG> of nodes, I'm creating a new element based on the array's key name. The XML MG> might look like this: MG> <rootElement> MG> <record id="1">Value 1</record> MG> <record id="2">Value 2</record> MG> </rootElement> MG> So I'd be doing this with DOMXML in a loop: $thisChild = $doc->>create_element($key); MG> $thisChild = $ancestor->append_child($thisChild); MG> Where $key is 'record' in this example, and $ancestor is 'rootElement', MG> which is carried along in the function. MG> The problem that when I reach the second element by the same name, and in MG> the same node level, I'm overwriting the $thisChild object that I just MG> created. How can I dynamically name these objects so that I can have an MG> indeterminate number of elements by the same name, in the same level? What I have done is to keep an array of elements so it would work like this $elements = array(); //loop if(!isset($elements[$key])){ $elements[$key] = $doc->create_element($key); } $thisChild = $ancestor->append_child($elements[$key]); //end loop -- regards, Tom

« previous php.general (#154464) next »