Thursday, 25 March 2010

Now the schema is loaded into MarkLogic, here are some rough notes on handling the "Schema Aware" facets of the server. Again, this information is pulled together from various MarkMail posts and a bit of trial and error:

Executing this should return the element. It should be noted that the formatted example, all the tags appear with lower-case element names. These will need to be changed back if you're following with the example schema and code.

To prove that the content is being validated against the schema, changing the date to something nonsensical (add a couple of random characters in, for example), should yield something like this:

These are some rough notes on techniques for using XML Schemas with MarkLogic.

Loading an XML Schema using cq:

The quickest way I've found to get a schema into your local MarkLogic instance is to copy your xsd file into your MarkLogic Docs folder (I also made a folder called schemas), then open a cq instance (or DQ if you prefer), select Schemas as your content source and use some XQuery like this:

Loading an XML Schema using XCC/J:

Another method would be to use XCC/J - I hope to write another post on this technique at another time with a more detailed example (note this method is untested at the time of writing):

After the cq process has been executed, running either:

or:

Should show you the schema.

It's important to note that when MarkLogic loads schemas into its database, it will put in any values that have defaults on load. This caused some confusion when I was testing the "Schema Aware" aspects of the server. I added the following attribute to my schema's parent element:

Here's a very basic example of a schema layout:

Most of this information is available elsewhere, so this post will hopefully serve to pull a few pieces together in the interests of saving time.