XRX/Move a Resource

Motivation
You want to create an XForms front end to an XQuery script that will move a resource from one collection to another collection or you want to move a collection from one location to another location.

Method
We will build a simple XForms front end to the xmldb:move operator. The syntax of the move operators is the following:

xmldb:move($from-collection, $to-collection, $resource)

Where:

$from-collection is the path name to the collection you are moving the file from $to-collection is the path name to the collection you are moving the file to  $resource in the name of the resource

If you are going to move a complete collection the format is:

xmldb:move($old-collection, $new-collection)

On this case the operation:

xmldb:move('/db/bar', '/db/foo')

would result in the bar collection being located inside the foo collection:

/db/foo/bar

To test this application create two test collections in your eXist database such as:

/db/from-collection /db/to-collection

Sample XForms Client
Create the following xhtml file:    Move Resource  From Collection:   To Collection:   Resource:   <xf:label>Move File</xf:label> </xf:submit>

Sample XQuery on Server
The following XQuery named "move.xq" should be placed in the same collection as the move.xhtml file.

Discussion
Now that you have the core move code done, you can enhance the program to browse to a specific collection for the source and browse to a specific collection for the destination. You can also create a listing of the resources in the source and destination folders.

Back: Autoincrement File ID • Next: Save File Dialog