Save XMLs into filesystem from DB
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
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 <dharam.mahi at gmail.com>:
Quoted text · Dharmendra Singh · 22 lines
> 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
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
Quoted text · Kristian Kankainen · 28 lines
On 06-Jul-2017 11:27 PM, "Kristian Kankainen" <kristian at 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 < > dharam.mahi at 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,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 > >
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 <dharam.mahi at gmail.com>:
Quoted text · DK Singh · 39 lines
> 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" <kristian at 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 < >> dharam.mahi at 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,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 >> >>
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 Regards Dharmendra Kumar Singh
Quoted text · Xavier-Laurent SALVADOR · 1 line
On Friday, 7 July 2017 12:09 AM, Xavier-Laurent SALVADOR <xavierlaurent.salvador at 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 <dharam.mahi at gmail.com>:
Quoted text · Xavier-Laurent SALVADOR · 36 lines
> 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" <kristian at 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 <dharam.mahi at 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
Written for BaseX 8.6. BaseX may have changed since: please check the current documentation.