View Single Post
Old 11-30-2007, 04:20 PM   #3 (permalink)
Salathe
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Nice little article, I was going to write something similar but without using the DOM. One thing to point out, to save us tired fingers, is an easier/quicker method of attaching simple element structures (ie, a node with just some text) to the document.

sketchMedia's example (copied from above)
PHP Code:
foreach($row as $fieldname => $fieldvalue)
{
    
$child $doc->createElement($fieldname);
    
$child $car->appendChild($child);
    
//add data to the new element
    
$value $doc->createTextNode($fieldvalue);
    
$value $child->appendChild($value);

Salathe's example
Everything will work the same, honest.
It's just a personal preference but I like this approach better for simple elements.

PHP Code:
foreach($row as $fieldname => $fieldvalue)
{
    
$car->appendChild($doc->createElement($fieldname$fieldvalue));

Salathe is offline  
Reply With Quote