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
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php