Understanding Schemas
A schema is a data dictionary for your XML content. To specify a schema, you need to define the namespace to which the schema applies as well as the location of the schema file.
Schemas define the types of elements within XML documents. When knowing the type of an XML element would be beneficial to evaluating an XQuery program, MarkLogic Server will look for the relevant schema document (based on that element's namespace) using this strategy:
If the XQuery program explicitly references a schema for the namespace in question, MarkLogic Server uses this reference.
Otherwise, MarkLogic Server searches the schema database for an XML schema document whose target namespace is the same as the namespace of the element that MarkLogic Server is trying to type.
If no matching schema document is found in the database, MarkLogic Server looks in its
Config
directory for a matching schema document.If no matching schema document is found in the
Config
directory, no schema is found.
Problems can arise in Step 2 above when there are multiple schema documents in the schema database whose target namespace matches the namespace of the element that MarkLogic Server is trying to type. In this case, it is convenient to be able to use the Admin Interface to specify a default mapping.
Schema mappings can be specified for the HTTP, ODBC, or XDBC servers individually or for the group to apply to all HTTP, ODBC, or XDBC servers in the group. If the schema mapping defined for an HTTP, ODBC, or XDBC server conflicts with the schema mapping defined for the group, the former mapping is used.
When you specify a schema mapping in the Admin Interface, MarkLogic Server uses this strategy to locate the schema:
First, MarkLogic Server searches the schema database for a document with the exact URI you specified in the schema mapping.
Note
If the schema mapping for the HTTP, ODBC, or XDBC server conflicts with the schema mapping for the group, the former mapping is used.
If no matching schema document is found in the schema database, MarkLogic Server looks in its
Config
directory for a schema document whose filename matches the filename portion of the URI you specified.If no matching schema document is found in the
Config
directory, no schema is found.
If a namespace is invoked by one or more data elements stored in a particular database, and the schema for that namespace is defined for the group or HTTP, ODBC, or XDBC server, MarkLogic Server applies the schema to the storage, indexing, and retrieval of that data.
Note
The schema database in this case is the schema database for the database in which the data is located.