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.

sinemetu1
  • 1,726
  • 1
  • 13
  • 24

1 Answers1

2

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";

(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 }
Sofia
  • 771
  • 1
  • 8
  • 22
  • I don't think you understood my question. The default attribute set in the schema on `xs:element` should make the value of `an_author` be `Faulkner` after a call to `validate`. Taken from the XML-Schema specification [here](http://www.w3.org/TR/xmlschema-0/#OccurrenceConstraints) "the schema processor provides the element with a value equal to that of the default attribute". – sinemetu1 Oct 30 '12 at 21:16
  • 1
    I suppose it's possible that she didn't understand your question, but having read the question, the answer, and your comment, it looks to me more as if you didn't understand the answer. Did you try the suggestion? Do you have an example showing that even after `declare option xdmp:output "default-attributes=yes";` the serialized document still doesn't have the default? Did you check with a path expression to see whether the default value is or is not actually showing up in the data model after your call to `validate`? – C. M. Sperberg-McQueen Nov 01 '12 at 01:01