1. XML 2 CSV
- Posted by ZNorQ Sep 12, 2016
- 1767 views
Hi,
Anyone know if there is a good library for converting xml 2 csv format? This includes xml tag attribute data..
Kenneth aka ZNorQ
2. Re: XML 2 CSV
- Posted by jmduro Sep 13, 2016
- 1743 views
In two steps:
- use http://www.rapideuphoria.com/xml_parser2.zip to convert XML string to a sequence
- use this to save this sequence as CSV
global function sequence2CSV(sequence section) -- converts a sequence to a CSV line -- CSV separator is a semicolon -- CSV strings are surrounded by quotes integer l sequence line if atom(section) then line = to_string(section) else l = length(section) line = {} if l > 0 then for j = 1 to l-1 do if atom(section[j]) or isDate(section[j]) then line &= to_string(section[j])&";" else line &= "\""&to_string(section[j])&"\";" end if end for if atom(section[l]) or isDate(section[l]) then line &= to_string(section[l]) else line &= "\""&to_string(section[l])&"\"" end if end if end if return line end function ------------------------------------------------------------------------------ global procedure saveCSV(sequence filename, sequence section) -- saves a sequence in a CSV file -- CSV separator is a semicolon -- CSV strings are surrounded by quotes integer f_out f_out = open(filename, "w") if f_out != -1 then for i = 1 to length(section) do puts(f_out, sequence2CSV(section[i])&"\n") end for close(f_out) end if end procedure ------------------------------------------------------------------------------ global procedure appendCSV(sequence filename, sequence section) integer f_out f_out = open(filename, "a") if f_out != -1 then for i = 1 to length(section) do puts(f_out, sequence2CSV(section[i])&"\n") end for close(f_out) end if end procedure
Jean-Marc
3. Re: XML 2 CSV
- Posted by ZNorQ Sep 15, 2016
- 1678 views
Jean-Marc,
I'm trying out the xml parser library, and from what I can understand I must run xml2sequence() function first, then run the data through your sequence2CSV() function...(?) However it uses a to_string() function that I can't find - could you please give me any pointers?
Regards, Kenneth aka ZNorQ
4. Re: XML 2 CSV
- Posted by euphoric (admin) Sep 15, 2016
- 1622 views
Jean-Marc,
I'm trying out the xml parser library, and from what I can understand I must run xml2sequence() function first, then run the data through your sequence2CSV() function...(?) However it uses a to_string() function that I can't find - could you please give me any pointers?
Regards, Kenneth aka ZNorQ
It's in the std/convert.e lib. You have that?
5. Re: XML 2 CSV
- Posted by ZNorQ Sep 15, 2016
- 1626 views
Jean-Marc,
I'm trying out the xml parser library, and from what I can understand I must run xml2sequence() function first, then run the data through your sequence2CSV() function...(?) However it uses a to_string() function that I can't find - could you please give me any pointers?
Regards, Kenneth aka ZNorQ
It's in the std/convert.e lib. You have that?
Ups, my bad, I assumed it was part of the library or something. Didn't think that it could be part of the standard libs.
Thanks though.
Kenneth aka ZNorQ
6. Re: XML 2 CSV
- Posted by petelomax Sep 16, 2016
- 1605 views
Ups, my bad, I assumed it was part of the library or something. Didn't think that it could be part of the standard libs.
FWIW, I'm glad you queried it (never heard of it either), gave me a reason to add it to Phix.
Pete