Well I've made a signifigant improvement to this function, and it's now the parsing operation is only something like 26 lines. It works flawlessly (so far) for XML that does not have repeat element names on the same level. Which seems to be bad form anyway, using similar element names and distinguishing them with attributes.
I'd still like the code to work with XML that did have similarly named elements in the same node level.. can you see anything in my DOMXML calls that might indicate the problem? Source: http://www.healthtvchannel.org/test/php2xml.phps -- 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