Wednesday 9 June 2010

Upload an XML File using WebDAV

This tutorial demonstrates how to:
  • configure a WebDAV client on Windows 7 to connect to an eXist-db database.
  • create an eXist-db collection using the WebDAV client.
  • upload an XML document to the eXist-db database using the WebDAV client.

WebDAV
WebDAV is a set of HTTP extensions specified in RFC-4918, that allow users to manage resources on remote servers. eXist-db has a WebDAV server interface. This interface allows a correctly configured client to treat eXist collections as if they were folders in a file system, and treat XML documents as if they were files in a file system. For example, this is Windows Explorer in Windows 7 using a WebDAV client to show the root of an eXist-db database:


For comparison, this is the same eXist-db database viewed using the eXist-db web admin client:


WebDAV Clients
There are many WebDAV clients to choose from. Windows 7 comes with a WebDAV client already built-in, but at the time of writing it is unreliable. It is implemented by means of MSDAIPP.DLL which has a long and varied history of buggy releases.

This tutorial uses the NetDrive WebDAV client v1.0.8.16 which is verified for use on Windows 7. The 32-bit version is free for personal use.

Setup the NetDrive Client
Download the NetDrive WebDAV client from http://www.netdrive.net/ then run the setup program to install it. Start NetDrive:


Click New Site then enter the following details:
  • Site name: exist
  • Site IP or URL: localhost/exist/webdav/db
  • Port: 8080
  • Server type: WebDav
  • Drive: Z:
  • Account: admin
  • Password: <your admin password>
  • Save password: Yes
  • Click Save

Click Connect and Windows Explorer will open. After a few seconds the eXist-db database root will be displayed:


Create a Collection
Within eXist-db, XML documents are stored inside collections so before you upload a file, you should first create a collection in which to store it:
  • In Windows Explorer, click New Folder.
  • Name the new folder test.
  • Open the folder by double-clicking on it.
Windows Explorer will show the contents of the new test collection, which will be empty:


Create an XML Document
Use a plain text editor (e.g. Notepad) to create a small text file containing only this text:
<hello>world</hello>

Save the file to NetDrive @ exist (Z:) in the test folder and name the file hi.xml:


Verify the Upload
To verify that hi.xml has been correctly saved to the eXist database, query it using the REST interface:
  • Open a web browser
  • Navigate to:
http://localhost:8080/exist/rest//db/test/hi.xml
In the browser, click View Source to see the XML data:


If you see XML data like that above, then the XML document hi.xml has been correctly saved to the test collection of the eXist database.