Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Jan 2011
    Location
    Somerset UK
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Can I convert XML to CSV easily?

    Hello, I have been asked to convert all of the stuff from here: http://www.rkwltd.com/xml2.php

    into a CSV file to be uploaded to an ecommerce website. Please could someone explain to me whether this is possible with some sort of conversion software, I have tried a few options after searching Google, but they either don't work or I am not doing it properly. I am really stuck and I have spent half a day trying to work it out. I do not know anything really about XML, I have a mac so I'm limited to applications. Can anyone either recommend an option or should I just tell the client I can't do it

    Thank you

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by paintersinn View Post
    Hello, I have been asked to convert all of the stuff from here: http://www.rkwltd.com/xml2.php

    into a CSV file to be uploaded to an ecommerce website. Please could someone explain to me whether this is possible with some sort of conversion software, I have tried a few options after searching Google, but they either don't work or I am not doing it properly. I am really stuck and I have spent half a day trying to work it out. I do not know anything really about XML, I have a mac so I'm limited to applications. Can anyone either recommend an option or should I just tell the client I can't do it

    Thank you
    download xml into a file, load xml in a spreadsheet, msoffice or openoffice, and export the data as csv.

    best regards

  • #3
    New to the CF scene
    Join Date
    Jan 2011
    Location
    Somerset UK
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry for being thick but could you please elaborate on the process....Thank you

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by paintersinn View Post
    Sorry for being thick but could you please elaborate on the process....Thank you
    1. download the xml from that url into a file
    2. load xml into openoffice or msoffice, both know how to load xml, i'm not sure but is possible to do same thing with google doc
    3. save the document as csv, using save as.

    after 2 and before 3 you can change the content to fix some problem if you need.

    best regards

  • #5
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Two XML to CSV conversion tools - 1 x Windows and 1 x Online

    Bit late, but I just finished an online web based converter for XML to CSV for those who are looking for an instantly available tool. You can find it at here. I also created open source XML to CSV conversion software that runs on the Windows platform. It is available from the codeplex website.

  • #6
    New to the CF scene
    Join Date
    May 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    I too couldn't find an easy script online so I wrote my own...

    :: ~ Flattens xml file into csv file
    :: ~ works well for standard/uniform XML data files
    :: ~ (if " and ^ expected in data then some post-processing required)
    :: ~ (if < and > expected in data then pre-casting expected tags to something without < or > which would then be searched for would be necessary)
    :: ~ see Usage for params
    :: ~ Glenn Babic 05-May-2012

    @echo off
    setlocal EnableDelayedExpansion

    if "%~1"=="" goto Usage

    set xml_file=%~1
    for /f %%a in ('dir /b "%xml_file%"') do set csv_file=%%~na.csv&set tmp_file=%%~na.tmp
    IF EXIST "%tmp_file%" del "%tmp_file%"
    set colList=%~2
    if "%3=%4"=="header=Y" echo %colList% >> "%tmp_file%"
    :: ~ initialise tagVars
    call:InitTagVars "%colList%"
    set colList=,%colList%,
    for /f "tokens=*" %%a in ('findstr /I /R "<.*>.*</.*>" "%xml_file%"') do call:ProcessTag "%%a"
    :: ~ print final row
    call:ProcessCompleteRow
    move /Y "%tmp_file%" "%csv_file%" >NUL
    goto:EOF

    :ProcessTag
    for /f "tokens=1,2 delims=<>" %%a in (%1) do set tagName=%%a&set tagValue="%%b"
    :: ~ check if tag in required list
    if "!colList:,%tagName%,=!"=="%colList%" goto:eof
    :: ~ if null (tagValue actually got set as end tag) then set tag to null
    if %tagValue%=="/%tagName%" set tagValue=""
    :: ~ check if tag is higher rank or same as previous tag and if so print current row
    for /f "tokens=1,2 delims=^|" %%a in ("{top}!colList:,%tagName%,=^|,%tagName%,!") do set lowerTags=%%b
    if "!lowerTags:,%prevTagName%,=!" NEQ "!lowerTags!" call:ProcessCompleteRow
    :: ~ eg. for tag GasDay create variable v_GasDay="%tagValue%"
    set v_%tagName%=%tagValue%
    set prevTagName=%tagName%
    goto:EOF

    :ProcessCompleteRow
    set varCmd=!colList:,=%%^^,%%v_!
    :: ~ eg. turn GasDay,NetworkID into %v_GasDay%,%v_NetworkID% etc
    for /f "tokens=*" %%a in ('echo %varCmd:~2,-4% ^>^> "%tmp_file%"') do NUL
    :: ~ clear lower ranking tag values
    call:InitTagVars "%lowerTags:~1,-1%"
    goto:EOF

    :InitTagVars
    :: ~ eg. turn GasDay,NetworkID into set v_GasDay=""&set v_NetworkID="" etc.
    set varCmd=%~1
    set varCmd=set v_%varCmd:,==""^&set v_%=""
    %varCmd%
    goto:EOF

    :Usage
    echo xml2csv "xmlFileName" "requiredXmlTags" [header=Y]
    echo.
    echo xmlFileName: XML file. CSV file created with same name.
    echo requiredXmlTags: selected Xml Tags to translate into CSV columns
    echo (Order must be same as XML file ranking/ordering, which must be constant).
    echo header=Y first line in CSV output as header of column names.
    Last edited by ozoutofwater; 05-07-2012 at 02:22 PM.

  • #7
    New to the CF scene
    Join Date
    May 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    There are many online tools which you could use like "Zamzaar".

  • #8
    New to the CF scene
    Join Date
    Aug 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I would recommend to give XMLStarlet a try. Works like charm as it iterates through the document and allows to specify the values of the separate columns using XPath. Sounds more complicated than it is. I wrote a tutorial with several examples. Check it out!

    Transforming an XML Document into a CSV using XMLStarlet | joy of data


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •