Monday 7 June 2010

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":





No comments:

Post a Comment