Converting xml to csv files....

This is a discussion on Converting xml to csv files.... within the Tech Board forums, part of the Community Boards category; Hi, I have a number of xml files which need to be converted into csv files - which would be ...

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    21

    Converting xml to csv files....

    Hi,

    I have a number of xml files which need to be converted into csv files - which would be the best method to do this using C (I have use of an oracle db if need be)?

    Ta,

    Manny

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    So is doing this in C a requirement, or just a suggestion on your part because it's the only language you know?

    Because my first reaction to this problem would be to use Perl.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Jun 2006
    Posts
    21
    Yes, doing it it in C is a requirement (and the only language I know a little about).

    Out of curiosity, which language would this be the easiest to do this in?

    Quote Originally Posted by Salem View Post
    So is doing this in C a requirement, or just a suggestion on your part because it's the only language you know?

    Because my first reaction to this problem would be to use Perl.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Perl sounds like an excellent choice for this - I'm no Perl expert, but translating text from one format to another is typically something that Perl does REALLY well.

    Alternatively, try to find some XML library that you can use with C...

    --
    Mats

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    http://expat.sourceforge.net/ is one such library, which coincidentally is also available via a perl module.

    Unless this is homework, I see no reason to write this in C.

    For me, the only issue is how long does it take to write the program. It might take days of messing about with C's primitive string handling, and for what - a program you run once on a handful of files and then throw away?

    To me, this is a 5-minute lash-up in Perl, coupled with a quick test to make sure it's likely to run in minutes rather than weeks. Then set it going on the whole lot and go and have lunch.

    Most of the programs time is going to be spent in file I/O anyway, so the performance improvement of C isn't going to be that great.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Registered User
    Join Date
    Jun 2006
    Posts
    21
    Hmmm, I'm afraid I don't know Perl - and its not for homework.
    I guess I'll take a look at expat and take it from there.

    Thanks.

    Quote Originally Posted by Salem View Post
    http://expat.sourceforge.net/ is one such library, which coincidentally is also available via a perl module.

    Unless this is homework, I see no reason to write this in C.

    For me, the only issue is how long does it take to write the program. It might take days of messing about with C's primitive string handling, and for what - a program you run once on a handful of files and then throw away?

    To me, this is a 5-minute lash-up in Perl, coupled with a quick test to make sure it's likely to run in minutes rather than weeks. Then set it going on the whole lot and go and have lunch.

    Most of the programs time is going to be spent in file I/O anyway, so the performance improvement of C isn't going to be that great.

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    If you are "strong" at C string handling, you will probably be ok with using C. If you struggle to use strcpy, strstr and such functions, then I would suggest that learning Perl is no more difficult than to write the code and fix the inevitible bugs in C.

    A few google finds:
    http://www.fredshack.com/docs/perl.html
    http://www.rexswain.com/perl5.html

    Guide to Perl regular expressions (this will help you parse/translate XML):
    http://www.biotek.uio.no/EMBNET/guides/guideRegExp.pdf

    --
    Mats

  8. #8
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    When I did some XML / Perl stuff recently, I cribbed stuff from here - http://www.xml.com/lpt/a/313
    Once you've got to the stage of printing out start/end elements and attribute/value pairs, then it should be pretty easy to get to reformatting the data you want.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  9. #9
    Registered User
    Join Date
    Jun 2006
    Posts
    21
    Thanks.

    I will stick with using C for now. Perl does look like a good option but I'm a little hesitant to try it out as I'd like more experience of C at present - but Perl is definately something I will look in to for the future.

  10. #10
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    My language of choice for this task would actually be XSLT.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Error opening files in a different dir
    By Ozzie in forum C++ Programming
    Replies: 3
    Last Post: 10-09-2008, 06:55 AM
  2. Program Deployment and DLL/OCX Files?
    By dfghjk in forum C++ Programming
    Replies: 5
    Last Post: 06-16-2008, 02:47 AM
  3. accessing all files in a folder.
    By pastitprogram in forum C++ Programming
    Replies: 15
    Last Post: 04-30-2008, 10:56 AM
  4. Converting image files to ASCII
    By Culoki in forum Game Programming
    Replies: 6
    Last Post: 09-30-2005, 09:43 PM
  5. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21