Save XMLs into filesystem from DB
Thursday, 6 July 2017 · 5 messages · last reply 7 Jul 2017
DS
Dharmendra Singh6 Jul 2017 12:42 #
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 SinghKK
Kristian Kankainen6 Jul 2017 19:57 #
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
DS
DK Singh6 Jul 2017 20:06 #
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 exampleQuoted 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 > >
XS
Xavier-Laurent SALVADOR6 Jul 2017 20:39 #
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 >> >>
--
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*.
DS
Dharmendra Singh7 Jul 2017 09:38 #
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 SinghQuoted 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
--
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.
Written for BaseX 8.6. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery