On Thu, 08 Oct 2009 06:04:50 -0700, <[email protected]> wrote:


Hi Michael,
I have followed all the steps those you have discussed in your tutorial at http://developer.marklogic.com/howto/tutorials/2007-04-schema.xqy . I tested it and it is working fine as per your tutorial. The problem is when change the tutorial.xml <born> field data from a valid date by a string, and then I load this tutorial.xml again into the database; this time it should not be loaded into the database because it is not the proper xml according the tutorial.xsd. But it is loaded successfully into the database. I mean to say while I load a new document then MarkLogic xml schema validation is not working.

Please help me out. What I need to do so that when I load a new xml file into the database then MarkLogic should validate it before loading ,and if it is not correct then MarkLogic should throw some error.

Regards,
Anuj Kumar

Validation (and reporting of errors) is only performed in XQuery via
the validate expression (you can validate individual elements: it doesn't
have to be the whole document, FYI):

validate strict { fn:doc("mydoc.xml") }

This expression will throw an error if the node was invalid per the
schema or if no schema was found.

Schema information is used on load only to assist in repair (if you have
repair turned on) and to determine whitespace handling.  Validation is
not performed on load.  You may want to load invalid content and use
XQuery to fix it up, and you can do this.  Schema information is also
used to obtained type information as required in a particular query.
For example, if you have a function with an argument declared to be
of a particular type, MarkLogic Server will make use of schema information
to check that.  If you ask for a typed value (e.g. via fn:data) schema
information is used to return you an item of the proper type, and you
may get a type error at that point.  In your document above,
fn:data on the born element would give you an error,  as would
a call to the validate expression.

If what you want to do is validate each document you load into the
database, you need to make a load script that does that, e.g.

  xdmp:document-insert("/db/path/mydoc.xml",
    validate strict { xdmp:document-get("/example/mydoc.xml") } )

//Mary

[email protected]
Principal Engineer
Mark Logic Corporation
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general

Reply via email to