<?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>
Tôi cố gắng để chuyển đổi xml này vào csv Tôi đã thử một số điều như thế này nhưng tôi không nhận được bất kỳ logic để chuyển đổi dữ liệu sang định dạng csvlàm thế nào để chuyển đổi tập tin xml vào tập tin csv trong javascript
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 I want array of string data);
csw.writeEndDocument();
csw.close();
fileWriter.close();
}
catch(e) {
return PIPELET_ERROR;
}
Nhưng tôi không biết cách tôi có thể chuyển đổi dữ liệu xml thành chuỗi của mảng
Xem http://stackoverflow.com/questions/7949752/cross-browser-javascript-xml-parsing để biết cách phân tích cú pháp XML thành đối tượng JavaScript. Sau đó, bạn chọn các bit bạn muốn đặt trong mảng của mình. –