how to convert xml file into csv file in javascript -


<?xml version="1.0" encoding="utf-8"?> <current>    <city id="1259229" name="pune">       <coord lon="73.86" lat="18.52" />       <country>in</country>       <sun rise="2016-01-07t01:38:29" set="2016-01-07t12:42:53" />    </city>    <temperature value="27.49" min="27.49" max="27.49" unit="metric" />    <humidity value="43" unit="%" />    <pressure value="955.13" unit="hpa" />    <wind>       <speed value="2.65" name="light breeze" />       <gusts />       <direction value="113.502" code="ese" name="east-southeast" />    </wind>    <clouds value="36" name="scattered clouds" />    <visibility />    <precipitation mode="no" />    <weather number="802" value="scattered clouds" icon="03d" />    <lastupdate value="2016-01-07t06:25:45" /> </current> 

i trying convert xml csv have tried thing not getting logic convert data csv format

       try {             var file : file = new file(dw.io.file.impex + '/src/weather.csv');             var filewriter : filewriter = new filewriter(file, 'utf-8');             var csw : csvstreamwriter = new csvstreamwriter(filewriter);             csw.writenext(//here want array of string data );             csw.writeenddocument();             csw.close();             filewriter.close();         }         catch(e) {             return pipelet_error;         } 

but don't know how can convert xml data strings of array

as you're using server-side javascript, demandwarescript, check xmlstreamreader class , e4x syntax. https://en.m.wikipedia.org/wiki/ecmascript_for_xml e4x ecmascript xml, proprietary syntax used xml dom access in demandware. need 1 more file object reading xml file.

also xml file not "flat", need define xml elements go in csv.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -