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.

Monday 7 June 2010

Upload an XML File using the Web Client

The eXist-db Database Administration Web Client (web client for short) is a simple browser-based interface which allows you to - amongst other things - upload an XML document to an eXist-db database.

This tutorial demonstrates how to upload an XML document to an eXist-db database using the web client.

Start the Web Client
To start the eXist-db web client, either click this link, or open a web browser and navigate to:
http://localhost:8080/exist/admin/admin.xql
You will be presented with the Web Client login page:


Type in your admin password if you created one, then click Submit. You will then be presented with the Web Client database admin home page which looks something like this:


Create a Collection
Within eXist-db, XML documents are stored inside collections. So before you upload a documente, you should first create a collection in which to store it:
  1. From the menu on the left of the page, click "Browse collections".
  2. In the "New collection" textbox, type "test" (without the quotes).
  3. Click the "Create Collection" button.
You will see that a new collection "test" has been created:


Create an XML Document
Now create a small XML document. Use a plain text editor (e.g. Notepad) to create a text file containing only this text:
<hello>world</hello>
Save the file to your desktop and give it a filename of hi.xml:


Store the XML Document in the eXist-db Database
Back in the web client page, click the "test" collection you created earlier. You will see the contents of the "test" collection, which will be empty:


Click the "Choose File" button. A "file open" dialog box will appear. Select the "hi.xml" file you created then click the "Open" button.

Click the "Upload" button to upload hi.xml into the "test" collection of the eXist-db database:


Verify that the XML Data has been UpLoaded
To check that the XML file has been stored in the eXist-db database, you can view it directly using the web client. Click on the "hi.xml" link to view the XML output:


To view the XML source data, choose "View source" in your browser:

Upload an XML File Using the Admin Client

An easy way to add XML data to an eXist-db database is by using the eXist-db Admin Client. This tutorial will show you how to upload an XML file to an eXist-db database using the eXist-db Admin Client tool.


Start the Admin Client
Download a file called "exist.jnlp" either by going to http://exist-db.org/index.html and clicking on Webstart Client or by clicking on this link. When the file has downloaded, open it to start the Admin Client. The database login dialog box will be shown:



Change the URL to:
xmldb:exist://127.0.0.1:8080/exist/xmlrpc
Enter your password if you created one, then click OK. The eXist Admin Client will open:


Create a Collection
Within eXist-db, XML data is stored inside collections. So before you upload a data file, you should first create a collection in which to store it:

  1. Click the "Create new collection" icon.
  2. In the dialog box that appears, type "test" (without the quotes) and click OK.

You will see that a new collection called "test" has been created:



Create an XML Data File
You now need to create a small XML data file. Use a plain text editor (e.g. Notepad) to create a text file containing only this text:
<hello>world</hello>
Save the file to your desktop and give it a filename of "hi.xml" (without the quotes):



Store the XML File in the eXist-db Database
Back in the eXist Admin Client program, double-click the "test" collection you created earlier. The Admin Client will now show the contents of the "test" collection, which will be empty:


Click the "Stores one or more files to the database" icon and a dialog box will open. Select the "hi.xml" file you created then click the "Select files or directories to store" button. A progress dialog box will appear:


Click the "Close" button. The Admin Client will now show the "test" collection containing the "hi.xml" file you just uploaded:


Verify that the XML Data has Been Stored
To check that the XML data has been stored in the eXist-db database, you can use the XPath/XQuery tool built into the Client Admin program:
  1. Click the "Query the database with XPath" button (the binoculars) to open the query tool.
  2. In the "Query Input:" pane of the query dialog, enter this XQuery command:

    /hello
  3. Click the "Submit" button.
Your XML document will be shown in the results pane, proving that the XML data you entered into the hi.xml file has been uploaded and stored in the eXist-db database in a collection called "test":