Hi again,
I've run into a small problem when using: let $csv := csv:serialize($result) return file:write-text($out, $csv)
The CVS that comes out only includes one line, and if I change the file:write-text to file:append-text-lines, the result doesn't really include all the information I need.
So, I tried a "dirty" approach where I used: let $result := concat ($name,',',$host,',',$path,',',$count,',',$time) return file:append-text-lines($out, $result)
Now this works, but I can't seem to find a way to add the headers to the first line of the file. Any ideas?
Thanks, Noam
On Tue, May 26, 2015 at 11:27 PM, Noam Green green.noam@gmail.com wrote:
That's perfect Christian.
Thanks so much! Noam
On Tue, May 26, 2015 at 10:48 PM, Christian Grün < christian.gruen@gmail.com> wrote:
Hi Noam,
My followup question is therefore - Is there a way I can run a batch
command
(e.g: Make_CSV.exe input.xml output.csv) where the XQuery would run
taking
as commands the input file name, output file name, and run?
That's indeed possible. You can e.g. bind XQuery variables when running BaseX on command-line:
Query (query.xq):
declare variable $in external; declare variable $out external;
let $result := doc($in)/any/path let $csv := csv:serialize($result) return file:write-text($out, $csv)
Command line:
basex -b in=input.xml -b out=output.csv query.xq
You can check out our Wiki for more details [1].
Hope this helps, Christian
[1] http://docs.basex.org/wiki/Command-Line_Options#Standalone
Thanks, Noam
On Tue, May 26, 2015 at 10:17 PM, Christian Grün <
christian.gruen@gmail.com>
wrote:
Dear Noam,
Welcome to the list. I guess the answer on your question mainly depends on what you have done so far, so feel free to give us some more information (e.g. the XQuery expression you wrote).
The following XQuery expression reads two XML documents, navigates to a certain path, serializes the resulting nodes as CSV and writes the result to a file:
for $doc in ('one.xml', 'two.xml') let $result := doc($doc)/any/path let $csv := csv:serialize($result) return file:write-text($doc || '.csv', $csv)
All the best, Christian (Grün)
On Tue, May 26, 2015 at 8:59 PM, Noam Green green.noam@gmail.com
wrote:
Hi,
I'm new to BaseX, so apologize if this is a repetitive question. I have created an XQuery which currently runs on a specific XML file. What I'd like to do is to be able to create a batch command, which
would
receive as input a different XML source file, run the XQuery command, and save the results in a CSV file.
Is there a way to do such a process?
Thanks, Noam