1

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.

Simplified 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>

The document:

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

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.

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

4

1 回答 1

2

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

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

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

(或者您可以将选项default-attributes设置为xdmp:quotexdmp:save。)

或者,您可以强制复制数据模型实例,它将携带所有属性,但忘记了它们是默认的:

let $d := validate strict { $node }
return document { $d }
于 2012-10-30T17:41:17.227 回答