Page 1 of 1

help: php code that can generate an xml file from a csv file

Posted: Mon Jul 09, 2007 8:49 am
by gothica
im not sure if this is the right section for my question, however here goes..

i haven't started any coding just yet however is there anyone here who have made a code that can generate an xml file from a csv file? can you share the code with so i can study it? i have ideas on how to approach this problem but i just though i'd take my chances that someone out there might have already done it. i'll appreciate any help on this matter. thanks in advance! :D

Posted: Mon Jul 09, 2007 10:58 am
by volka
can be as simple as

Code: Select all

...
$elementnames = array('one', 'two', 'three', 'four');
...
  $record = $dom->createElement('row');
  foreach($row as $key=>$val) {
    $element = $dom->createElement($elementnames[$key], $val);
    $record->appendChild($element);  
  }
  $dom->documentElement->appendChild($record);
...
depends on exactly what you're trying to achieve.

Posted: Tue Jul 10, 2007 4:52 am
by gothica
thanks for the tip. i'm already looking into it. i haven't coded in php for a long time now so i have to review a bit. :wink: