Discussion:
[basex-talk] Save XMLs into filesystem from DB
Dharmendra Singh
2017-07-06 10:42:58 UTC
Permalink
Hi All ,
i have to save the XMLs files from  the DB but i am not able to do that below is my code, this code is generating only one kb file  so can any one tell me where i am doing wrong
let $localpath := 'D:/2017/doctest/xmls'for $xmls in db:open('test')
return file:write($localpath,$xmls,map{"method": "xml"})
Note: i am able to do using import command but i don't have to copy all data from the DB i have to copy by URI

Thanks & Regards
Dharmendra Kumar Singh
Kristian Kankainen
2017-07-06 17:57:41 UTC
Permalink
DK Singh
2017-07-06 18:06:50 UTC
Permalink
Thanks for your reply Kristian

So I gone through the documentation and I found that function file:write
take parameters path and item so first parameters I am passing the local
directory path where documents has to be saved and second argument I am
passing the item

It will be very helpful if you provide the example
You only provide a path to file:write whichbgets overwritten by each
for-loop, so you end up with just one file with the contents of the last
run of the for-loop. You should instead provide a file name for each file
you want to write.
6. juuli 2017 1:42 PM kirjutas kuupÀeval Dharmendra Singh <
Hi All ,
i have to save the XMLs files from the DB but i am not able to do that
below is my code, this code is generating only one kb file so can any one
tell me where i am doing wrong
let $localpath := 'D:/2017/doctest/xmls'
for $xmls in db:open('test')
return file:write($localpath,$xmls,map{"method": "xml"})
Note: i am able to do using import command but i don't have to copy all
data from the DB i have to copy by URI
Thanks & Regards
Dharmendra Kumar Singh
Xavier-Laurent SALVADOR
2017-07-06 18:39:06 UTC
Permalink
Hello,
this is a mistake our students do many often:
--------
1. (:1- One file with all entries:)
2. file:write('D:\myBase.xml', <bdd>{for $x in /bdd return $x}</bdd>)
-------
1. (:Many files with one entry each:)
2. for $x at $count in //entry return file:write('D:\'||$count||'.xml', $x)
-------

Br
Post by DK Singh
Thanks for your reply Kristian
So I gone through the documentation and I found that function file:write
take parameters path and item so first parameters I am passing the local
directory path where documents has to be saved and second argument I am
passing the item
It will be very helpful if you provide the example
You only provide a path to file:write whichbgets overwritten by each
for-loop, so you end up with just one file with the contents of the last
run of the for-loop. You should instead provide a file name for each file
you want to write.
6. juuli 2017 1:42 PM kirjutas kuupÀeval Dharmendra Singh <
Hi All ,
i have to save the XMLs files from the DB but i am not able to do that
below is my code, this code is generating only one kb file so can any one
tell me where i am doing wrong
let $localpath := 'D:/2017/doctest/xmls'
for $xmls in db:open('test')
return file:write($localpath,$xmls,map{"method": "xml"})
Note: i am able to do using import command but i don't have to copy all
data from the DB i have to copy by URI
Thanks & Regards
Dharmendra Kumar Singh
--
Ce message peut contenir des informations réservées exclusivement à son
destinataire. Toute diffusion sans autorisation est interdite. Si vous
n'en êtes pas le destinataire, merci de prendre contact avec l'expéditeur
et de détruire ce message.

*This email may contain material for the sole use of the intended
recipient. Any forwarding without express permission is prohibited. If you
are not the intended recipient, please contact the sender and delete all
copies*.
Dharmendra Singh
2017-07-07 07:38:18 UTC
Permalink
Hi Mr.SALVADOR,
I got the solution what i was looking for:
let $dbpath  := '/test/'let $files := fn:uri-collection($dbpath)let $count := fn:count($files)let $zip   := archive:create(                           $files ! element archive:entry { . },                           $files ! bin:encode-string(fn:serialize((fn:doc(.))))                           )return file:write-binary('D:\2017\doctest\xml.zip', $zip)

Thanks and RegardsDharmendra Kumar Singh 

On Friday, 7 July 2017 12:09 AM, Xavier-Laurent SALVADOR <***@gmail.com> wrote:


Hello, this is a mistake our students do many often:--------1. (:1- One file with all entries:)
2.  file:write('D:\myBase.xml', <bdd>{for $x in /bdd return $x}</bdd>)
-------
1. (:Many files with one entry each:)
2. for $x at $count in //entry return file:write('D:\'||$count||'.xml', $x) -------
Br
2017-07-06 20:06 GMT+02:00 DK Singh <***@gmail.com>:

Thanks for your reply Kristian
So I gone through the documentation and I found that function file:write take parameters path and item so first parameters I am passing the local directory path where documents has to be saved and second argument I am passing the item 
It will be very helpful if you provide the example 
On 06-Jul-2017 11:27 PM, "Kristian Kankainen" <***@keeleleek.ee> wrote:

You only provide a path to file:write whichbgets overwritten by each for-loop, so you end up with just one file with the contents of the last run of the for-loop. You should instead provide a file name for each file you want to write.6. juuli 2017 1:42 PM kirjutas kuupÀeval Dharmendra Singh <***@gmail.com>:

Hi All ,
i have to save the XMLs files from  the DB but i am not able to do that below is my code, this code is generating only one kb file  so can any one tell me where i am doing wrong
let $localpath := 'D:/2017/doctest/xmls'for $xmls in db:open('test')
return file:write($localpath,$xmls,ma p{"method": "xml"})
Note: i am able to do using import command but i don't have to copy all data from the DB i have to copy by URI

Thanks & Regards
Dharmendra Kumar Singh
--
Ce message peut contenir des informations réservées exclusivement à son destinataire. Toute diffusion  sans autorisation est interdite. Si vous n'en êtes pas le destinataire, merci de prendre contact avec l'expéditeur et de détruire ce message.

This email may contain material for the sole use of the intended recipient. Any forwarding without express permission is prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
Loading...