The best way to learn about XQuery is to have a go with it.
So go get an XQuery engine and some XML.
To risk tooting my own horn, the best thing out there is MarkLogic Server.
For some XML I suggest the complete works of Shakespeare tagged for your enjoyment by John Bosak.
Got all that?
OK lets get things working.
In MarkLogic Server you need to first do the install and then follow the instructions to set up an admin user and get a trial license.
Then you need to create Forest to put content and a Database to manage it and an app server to access it.
This is laid out in some detail in the admin guide, but it boils down to:
- Access the admin interface, likely at http://localhost:8001
- Go to the Forest tab, select create. Enter a forest name of your liking and hit save.
- Go to the Database tab, select create. Enter a database name (likely the same). You can leave everthing else as it is. There's a lot there (the admin guide is 164 pages) and you can always change stuff later.
- Go to the groups tab, select Default and then App Servers. Select Create WebDav Server. Enter a name and pick a port (we like to use 7000 range for these) and select your database. Leave the rest.
- Then select Create HTTP server. Enter a name. Then enter '/modules' for root, pick a port (we like 8000s for these) and select your database for both the modules and database entry. Finally to avoid having a basic authentication pop up all the time, go to the bottom and for the authentication entry select ' application level' and select the admin user.
- Finally you will need a handy XQuery tool called CQ - go ahead and download this and unzip it somewhere
OK - so what do I do with all of this.
First you want to use Windows Explorer to connect to the WebDav server. Go to Network Places and Select Add network place. Use the wizard to connect to your WebDav server (likely http://localhost:7001)
Once you have this open as a window you should see nothing. Make a folder called 'modules' (sound familiar) and take the downloaded CQ app files and put them under that (in /modules/cq/).
To make sure this is all right, access the CQ app on web server you created - likely http://localhost:8002/cq. It should be nice and yellow. Keep this window open.
Then go back to windows explorer and make a '/content' folder. And take the downloaded Plays and copy them to that folder.
(please note, when you did that copy - you loaded the XML into MarkLogic Server).
Now go back to the CQ app and lets check out the content.
To see an entire play type this
doc('/content/[play filename].xml')
And hit the XML button. You should see the entire play.
If you page down past the case, you will see that there are a couple of simple elements like SPEECH, LINE and SPEAKER.
Lets do a simple XQuery to see who says what. In this example I've loaded As You Like It, so I know Orlando is a SPEAKER:
for $speech in //SPEECH[./SPEAKER eq "ORLANDO"]
return
$speech
And you get all the <SPEECH> nodes where Orlando is the speaker.
And Congratulations - that is XQuery!
Comments