saxon:validate
Performs validation of a node against schema definitions.
validate($node as node()?) ➔ map(xs:string, item()*)
Arguments | |||
| $node | node()? | The node to be validated |
Result | map(xs:string, item()*) |
validate($node as node()?, $options as map(xs:string, item()*) ➔ map(xs:string, item()*)
Arguments | |||
| $node | node()? | The node to be validated |
| $options | map(xs:string, item()* | Validation options |
Result | map(xs:string, item()*) |
validate($node as node()?, $options as map(xs:string, item()*, $params as map(xs:string, item()*) ➔ map(xs:string, item()*)
Arguments | |||
| $node | node()? | The node to be validated |
| $options | map(xs:string, item()* | Validation options |
| $params | map(xs:string, item()* | Validation parameters |
Result | map(xs:string, item()*) |
Details
Namespace: http://saxon.sf.net/
The saxon:validate
extension function performs validation of a node against schema definitions,
providing more control over the validation process than is available with standard XSLT and XQuery interfaces.
For example, it allows validation parameters to be supplied, and it returns detailed information about the
validation errors that were found (if any).
The first argument must be a document, element, or attribute node (the node to be validated). If an empty sequence is supplied, the function returns the empty sequence.
If the second and/or third arguments are omitted, the effect is the same as if empty maps were supplied for these arguments.
The second argument, $options
, gives options for how the validation is to be performed.
The entries that are recognized in this map are:
-
buildTree which if present must have the value
true()
orfalse()
or()
(default is()
). The value()
means that the tree that results from validation is returned if validation succeeds, and is not returned if validation fails. Setting this option tofalse()
means that it will not be returned in either case. Setting it totrue()
means that the tree will be returned even if validation is unsuccessful. Note that in this case type annotations in the returned tree are unreliable. Note also that references to nodes in the returned error list relate to node in the input tree, not the result tree. -
processContents which must have the value
strict
orlax
(default isstrict
. Indicates whether validation is strict or lax, according to the element name of the root element. The value is ignored if thetype
option is present. -
type whose value must be an
xs:QName
, being the name of a simple or complex type that is present in the schema at run time -
expandDefaults which must have the value
true()
orfalse()
(default istrue()
). Indicates whether the expansions of absent attributes and empty elements that have a schema-defined default value will be present in the returned tree.
The third argument, $params
, gives values of schema parameters declared using the
saxon:param
XSD extension (see ).
The keys must be xs:QName
values corresponding to the names of declared parameters, and the
corresponding values are the values to be used for the parameters.
The result of the function is a map. If validation succeeds, the map will contain two entries:
"node" is the validated node, and "valid" is the boolean value true. If validation fails, the map will
contain two entries: "valid" is the boolean value false, and "errors" is a list of error objects representing
the validation errors that were found. Each error object is itself a map, with the following optional entries
(all entries except message
are optional, and will be present only if information is
available):
-
message: A human-readable error message, as a string
-
code: An error code, as an xs:QName
-
specPart, constraint, clause: references to the XSD constraint that was violated, in the form of the XSD specification part number (1 or 2), the name of the constraint (e.g. "cvc-identity-constraint"), and the clause number within the constraint (e.g. "4.2.1")
-
node, path, lineNumber, columnNumber, systemId, publicId: information about the location of the error within the document or subtree being validated
Notes on the Saxon implementation
Available since Saxon 9.5