Interesting -- the clone_node() function does make certain that each element gets its own representation in the output, for any XML I tested. I guess then my problem lies with how I'm looping through the aforementioned array structure to get the values themselves.
Thanks, -- Matt Grimm Web Developer The Health TV Channel, Inc. (a non - profit organization) 3820 Lake Otis Parkway Anchorage, AK 99508 907.770.6200 ext. 686 907.336.6205 (fax) E-mail: [EMAIL PROTECTED] Web: www.healthtvchannel.org "Tom Rogers" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi, > > Thursday, July 10, 2003, 6:44:55 AM, you wrote: > MG> Tom: > > MG> Thanks for the help. Using the array setup you described, I end up with the > MG> value of each "record" node being appended to a single instance of the > MG> parent node. And that single instance of the parent node is the final one > MG> that was parsed (the attributes verify this). The example I used below is > MG> outputting this: > > MG> <rootElement> > MG> <record id="2">Value 1Value 2</record> > MG> </rootElement> > > MG> Any ideas? > > It seems we now have to clone nodes before using them. (php-4.3 +) > I did this as a test: > > $test =array( > 1=>array('type'=>'record','value'=>'Value 1','id'=>1), > 2=>array('type'=>'record','value'=>'Value 2','id'=>2)); > $elements = array(); > $doc = domxml_new_doc("1.0"); > //create a dummy document > ob_start(); > echo <<<END > <rootelement> > </rootelement> > END; > $buffer = ob_get_contents(); > ob_end_clean(); > $doc = domxml_open_mem($buffer); > //get the root element > $ancestor = $doc->document_element(); > //loop > foreach($test as $val){ > $key = $val['type']; > $value = $val['value']; > $id = $val['id']; > if(!isset($elements[$key])){ > $elements[$key] = $doc->create_element($key); > } > $thisChild = $ancestor->append_child($elements[$key]->clone_node());//<<<<clone > $thisChild->set_attribute('id',$id); > $txt = $doc->create_text_node($value); > $thisChild->append_child($txt); > } > //end loop > echo '<pre>'; > echo htmlentities($doc->dump_mem(true)); > echo '</pre>'; > > Gave me > <?xml version="1.0"?> > <rootelement> > <record id="1">Value 1</record><record id="2">Value 2</record></rootelement> > > -- > regards, > Tom > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php