MarkLogic中的默认架构值 [英] Default Schema Values in MarkLogic

查看:70
本文介绍了MarkLogic中的默认架构值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试通过xdmp:document-insert()插入文档之前,我正在通过validate strict { $xml }根据其各自的架构验证文档,并在insert调用中使用该输出.但是,validate调用的输出不包含模式中指定的默认值.

I'm trying to insert a document via xdmp:document-insert() before that is called I am validating the document against it's respective schema via validate strict { $xml } and using that output in the insert call. However the output of the validate call does not include the default value specified in the schema.

简化模式:

<xs:schema>
  <xs:complexType name="fields-type" abstract="false" mixed="false">
    <xs:sequence minOccurs="1" maxOccurs="1">
      <xs:element default="Faulkner" maxOccurs="1" minOccurs="0" name="an_author" nillable="false" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="document-type" abstract="false" mixed="false">
    <xs:sequence minOccurs="1" maxOccurs="1">
      <xs:element name="fields" type="fields-type" minOccurs="1" maxOccurs="1" nillable="false"/>
    </xs:sequence>
  </xs:complexType>
  <xs:element name="document" type="document-type" abstract="false" nillable="false"/>
</xs:schema>

文档:

 <document>
     <fields>
       <an_author/>
     </fields>
 </document>

在调用validate strict { $xml }之后,输出文档与上面的相同,没有任何默认值添加到<an_author>元素中.注意:我也尝试在架构中使用fixed属性代替default,并且得到相同的结果. xdmp:validate($xml, "strict")也不返回任何错误.

After calling validate strict { $xml } the output document is the same as above with no default value added to the <an_author> element. Note: I also tried using the fixed attribute in place of default in the schema and I'm getting the same result. xdmp:validate($xml, "strict") isn't returning any errors either.

根据XQuery验证规范此处,输出应具有指定的默认值.

According to the XQuery validate specification here the output should have the default value specified.

推荐答案

默认值实际上是数据模型的一部分,但是当我们输出数据模型时,它们不一定要序列化.您可以通过对默认属性进行路径表达式来验证默认属性是否在数据模型中.

The default values are in fact part of the data model, but they aren't necessarily serialized when we output the data model. You can verify that the default attributes are in the data model by doing a path expression against them.

如果要确保它们在输出中被序列化,则有一个输出设置将强制将它们发出:

If you want to make sure they get serialized on output, there is an output setting that will force them to be emitted:

declare option xdmp:output "default-attributes=yes";

(或者您可以在xdmp:quotexdmp:save上设置选项默认属性.)

(Or you can set the option default-attributes on xdmp:quote or xdmp:save.)

或者,您可以强制执行数据模型实例的副本,该副本将携带所有属性,但会忘记默认属性:

Alternatively, you can force a copy of the data model instance, which will carry all the attributes along, but forgets that they were defaulted:

let $d := validate strict { $node }
return document { $d }

这篇关于MarkLogic中的默认架构值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆