Hi Mary,
Then what is the Way to ensure that always my xml should be
validated against the xsd.(while insert, update operations.). I am using
4.0-2 version of Marklogic server.
When i tried using the XQuery validate {} expression. It is giving "
Element declaration not found for validated node in strict mode" for all
tye cases.
Case 1: when i give book node with extra element "<bk:author>Santhosh
</bk:author>". This is acceptable.
xdmp:node-insert-child($b, validate strict { <bk:book>
<bk:title>Arts</bk:title>
<bk:price>200</bk:price>
<bk:author>Santhosh </bk:author>
</bk:book> } )
Case 2: It is giving the same error whem i try to add correct
elements.(i.e) adding only the elements present in the xsd.
xdmp:node-insert-child($b, validate strict { <bk:book>
<bk:title>Arts</bk:title>
<bk:price>200</bk:price>
</bk:book> } )
<error:code>XDMP-VALIDATENODECL</error:code>
<error:name>err:XQDY0084</error:name>
<error:xquery-version>1.0-ml</error:xquery-version>
<error:message>Element declaration not found for validated node in
strict mode</error:message>
Thanks and Regards,
Santhosh Rajasekaran
"Mary Holstege" <[email protected]>
Sent by: [email protected]
05/22/2009 08:57 PM
Please respond to
General Mark Logic Developer Discussion <[email protected]>
To
"General Mark Logic Developer Discussion"
<[email protected]>
cc
Subject
Re: [MarkLogic Dev General] Xml schema validation problem - reg.,
On Fri, 22 May 2009 01:09:44 -0700, Santhosh Raj <[email protected]>
wrote:
> Hi all,
>
> I have created a library.xsd file and a library.xml file which
> will use that library.xsd file.
>
> I have loaded the library.xsd file into my schema database.
>
> Then I loaded library.xml file into my Documents database In Marklogic
> server.
>
> When I fire the following query:
>
> declare namespace bk = "http://www.harmony.com";
> doc("library.xml")//bk:book[1]/descendant::element(*,xs:string)
>
> It gives the correct answer. i.e It returns the descendant element of
> first book whose element type is xs:string.
>
> This implies that the xml is refering to that xsd.So it is populating
the
> the element matching the datatype xs:string which is specified in the
> xsd.
What happens is this: when you perform a type-aware operation (fn:data,
type test, etc.) we attempt to determine what the type of the node is.
You can think of this as the type-assignment part of schema assessment,
without the validation part. Note that this is done on-demand: we do
not persist type information in the database. As such, your query above
is a relatively expensive operation: you fetch every descendant node of
every book, figure out the type for that node, and then filter out the
ones that match.
> But when i try to update the xml using xdmp:node-insert-child() it is
not
> validating the content with the xsd. Even though if i add an extra
> element which is not present in the xsd it is adding to the xml. What
> is the
> problem? Is there any option to specify the xml to validate against xsd.
>
> When i try it , it is still adding to the xml. But actually it should
> not.
It is doing what it is supposed to: schema-validity is not required of
XML stored in the database. You don't even have to have a schema,
and being able to store invalid XML allows you to use XQuery to
clean up the bad XML.
> declare namespace bk = "http://www.harmony.com";
> for $b in doc("library.xml")//bk:books
> return
> xdmp:node-insert-child($b,<bk:book>
> <bk:title>Arts</bk:title>
> <bk:price>200</bk:price>
> <bk:author>Santhosh </bk:author>
> </bk:book>)
>
> In this example <bk:author>Santhosh </bk:author> Element is not
> present in the xsd, but still it is adding to the xml.
>
> What should be done to achieve this.(validating the xml against the xsd)
You need to use the XQuery validate {} expression.
For the query you have above, it would look something like:
declare namespace bk = "http://www.harmony.com";
for $b in doc("library.xml")//bk:books
return
xdmp:node-insert-child($b, validate strict { <bk:book>
<bk:title>Arts</bk:title>
<bk:price>200</bk:price>
<bk:author>Santhosh </bk:author>
</bk:book> } )
In the current version of ML (4.0) it does not yet do full checking,
however,
although it will in 4.1. In particular, it does not check the complex
type
constraints (e.g. which children are required, etc.)
//Mary
[email protected]
Principal Engineer
Mark Logic Corporation
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general
ForwardSourceID:NT0000BD46
=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain
confidential or privileged information. If you are
not the intended recipient, any dissemination, use,
review, distribution, printing or copying of the
information contained in this e-mail message
and/or attachments to it are strictly prohibited. If
you have received this communication in error,
please notify us by reply e-mail or telephone and
immediately and permanently delete the message
and any attachments. Thank you
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general