Modifying CSV node
Monday, 22 June 2015 · 5 messages
NG
Noam Green22 Jun 2015 10:09 #
Hi all,
I'm using the following xquery (after being helped by Christian).
declare variable $in external;
declare variable $out external;
declare variable $vendor external;
let $options := map { 'header': true() }
let $text := file:read-text($in)
let $xml := csv:parse($text, $options)
let $result := <csv>{
for $record in $xml//record[contains(VENDORS, $vendor) and
not(contains(HOST, "Non external")) and not(empty(HOST))]
return <record>{
$record/(HOST, PATH, ATTACKCOUNT, TIME_STAMP,CK)
}</record>
}</csv>
return file:write-text($out, csv:serialize($result, $options))I would like to have one of the returned records encrypted. How do I change that record before saving it?
I tried:
return <record>{
crypto:encrypt($record/CK, 'symmetric','keykeyke','DES'),
$record/(HOST, PATH, ATTACKCOUNT, TIME_STAMP,CK)
}</record>But that doesn't really change the CK field. I can't seem to modify anything in the $record/(
HOST, PATH, ATTACKCOUNT, TIME_STAMP,CK).
Any thoughts?
Thanks,
NoamCG
Christian Grün22 Jun 2015 10:30 #
Hi Noam,
Could you please provide us with a self-contained example (the smaller, the better [1])?
Thanks in advance,
Christian
[1] http://sscce.org/
Quoted text · Noam Green · 40 lines
On Mon, Jun 22, 2015 at 10:09 AM, Noam Green <green.noam at gmail.com> wrote: > Hi all, > > I'm using the following xquery (after being helped by Christian). > > declare variable $in external; > declare variable $out external; > declare variable $vendor external; > > let $options := map { 'header': true() } > let $text := file:read-text($in) > let $xml := csv:parse($text, $options) > > let $result := <csv>{ > for $record in $xml//record[contains(VENDORS, $vendor) and > not(contains(HOST, "Non external")) and not(empty(HOST))] > > return <record>{ > > $record/(HOST, PATH, ATTACKCOUNT, TIME_STAMP,CK) > }</record> > > }</csv> > return file:write-text($out, csv:serialize($result, $options)) > > I would like to have one of the returned records encrypted. How do I change > that record before saving it? > I tried: > return <record>{ > > crypto:encrypt($record/CK, 'symmetric','keykeyke','DES'), > $record/(HOST, PATH, ATTACKCOUNT, TIME_STAMP,CK) > }</record> > > But that doesn't really change the CK field. I can't seem to modify anything > in the $record/(HOST, PATH, ATTACKCOUNT, TIME_STAMP,CK). > > Any thoughts? > Thanks, > Noam
NG
Noam Green22 Jun 2015 12:07 #
Sorry - Just noticed I sent it to Christian only instead of to the group as well.
Resending.
====
Hi Christian,
Thanks for the quick reply.
The attacked CSV is very small.
I've also included the test query file.
As mentioned, I'd like to encrypt the CK field (so that it's saved to the file as encrypted).
Thanks,
Noam
Quoted text · Christian Grün · 60 lines
On Mon, Jun 22, 2015 at 11:30 AM, Christian Grün <christian.gruen at gmail.com> wrote: > Hi Noam, > > Could you please provide us with a self-contained example (the > smaller, the better [1])? > > Thanks in advance, > Christian > > [1] http://sscce.org/ > > > > > > > On Mon, Jun 22, 2015 at 10:09 AM, Noam Green <green.noam at gmail.com> wrote: > > Hi all, > > > > I'm using the following xquery (after being helped by Christian). > > > > declare variable $in external; > > declare variable $out external; > > declare variable $vendor external; > > > > let $options := map { 'header': true() } > > let $text := file:read-text($in) > > let $xml := csv:parse($text, $options) > > > > let $result := <csv>{ > > for $record in $xml//record[contains(VENDORS, $vendor) and > > not(contains(HOST, "Non external")) and not(empty(HOST))] > > > > return <record>{ > > > > $record/(HOST, PATH, ATTACKCOUNT, TIME_STAMP,CK) > > }</record> > > > > }</csv> > > return file:write-text($out, csv:serialize($result, $options)) > > > > I would like to have one of the returned records encrypted. How do I > change > > that record before saving it? > > I tried: > > return <record>{ > > > > crypto:encrypt($record/CK, 'symmetric','keykeyke','DES'), > > $record/(HOST, PATH, ATTACKCOUNT, TIME_STAMP,CK) > > }</record> > > > > But that doesn't really change the CK field. I can't seem to modify > anything > > in the $record/(HOST, PATH, ATTACKCOUNT, TIME_STAMP,CK). > > > > Any thoughts? > > Thanks, > > Noam >
CG
Christian Grün22 Jun 2015 12:52 #
Hi Noam,
The
crypto:encrypt function returns the result as a string, so you'll need to wrap it with an additional element: return <record>{
<CK>{ crypto:encrypt(...) }</CK>, ...
}</record>However, the returned string will contain non-ASCII characters, so it may not be what you expect, so you could possibly encode it as Base64:
convert:string-to-base64( ... )Hope this helps,
Christian
NG
Noam Green22 Jun 2015 14:02 #
Hi Christian,
As usual - fast and accurate response. Worked thanks!
What I guess I was missing is the <CK>{ } </CK> notation (all these little FLOWR tricks I can't seem to find anywhere).
Thanks again,
Noam
Quoted text · Christian Grün · 19 lines
On Mon, Jun 22, 2015 at 1:52 PM, Christian Grün <christian.gruen at gmail.com> wrote: > Hi Noam, > > The crypto:encrypt function returns the result as a string, so you'll > need to wrap it with an additional element: > > return <record>{ > <CK>{ crypto:encrypt(...) }</CK>, ... > }</record> > > However, the returned string will contain non-ASCII characters, so it > may not be what you expect, so you could possibly encode it as Base64: > > convert:string-to-base64( ... ) > > Hope this helps, > Christian >
Written for BaseX 8.2. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery