fn.deepEqual

```fn.deepEqual(
parameter1 as Sequence,
parameter2 as Sequence,
[collation as String]
) as Boolean```

Summary

This function assesses whether two sequences are deep-equal to each other. To be deep-equal, they must contain items that are pairwise deep-equal; and for two items to be deep-equal, they must either be atomic values that compare equal, or nodes of the same kind, with the same name, whose children are deep-equal. This is defined in more detail below. The \$collation argument identifies a collation which is used at all levels of recursion when strings are compared (but not when names are compared), according to the rules in 7.3.1 Collations.

If the two sequences are both empty, the function returns true.

If the two sequences are of different lengths, the function returns false.

If the two sequences are of the same length, the function returns true if and only if every item in the sequence \$parameter1 is deep-equal to the item at the same position in the sequence \$parameter2. The rules for deciding whether two items are deep-equal follow.

Call the two items \$i1 and \$i2 respectively.

If \$i1 and \$i2 are both atomic values, they are deep-equal if and only if (\$i1 eq \$i2) is true. Or if both values are NaN. If the eq operator is not defined for \$i1 and \$i2, the function returns false.

If one of the pair \$i1 or \$i2 is an atomic value and the other is a node, the function returns false.

If \$i1 and \$i2 are both nodes, they are compared as described below:

If the two nodes are of different kinds, the result is false.

If the two nodes are both document nodes then they are deep-equal if and only if the sequence \$i1/(*|text()) is deep-equal to the sequence \$i2/(*|text()).

If the two nodes are both element nodes then they are deep-equal if and only if all of the following conditions are satisfied:

1. the two nodes have the same name, that is (node-name(\$i1) eq node-name(\$i2)).
2. the two nodes are both annotated as having simple content or both nodes are annotated as having complex content.
3. the two nodes have the same number of attributes, and for every attribute \$a1 in \$i1/@* there exists an attribute \$a2 in \$i2/@* such that \$a1 and \$a2 are deep-equal.
4. One of the following conditions holds:
• Both element nodes have a type annotation that is simple content, and the typed value of \$i1 is deep-equal to the typed value of \$i2.
• Both element nodes have a type annotation that is complex content with elementOnly content, and each child element of \$i1 is deep-equal to the corresponding child element of \$i2.
• Both element nodes have a type annotation that is complex content with mixed content, and the sequence \$i1/(*|text()) is deep-equal to the sequence \$i2/(*|text()).
• Both element nodes have a type annotation that is complex content with empty content.

If the two nodes are both attribute nodes then they are deep-equal if and only if both the following conditions are satisfied:

1. the two nodes have the same name, that is (node-name(\$i1) eq node-name(\$i2)).
2. the typed value of \$i1 is deep-equal to the typed value of \$i2.

If the two nodes are both processing instruction nodes or namespace bindings, then they are deep-equal if and only if both the following conditions are satisfied:

1. the two nodes have the same name, that is (node-name(\$i1) eq node-name(\$i2)).
2. the string value of \$i1 is equal to the string value of \$i2.

If the two nodes are both text nodes and their parent nodes are not object nodes, then they are deep-equal if and only if their string-values are both equal.

If the two nodes are both text nodes and their parent nodes are both object nodes, then they are deep-equal if and only if their keys and string-values are both equal.

If the two nodes are both comment nodes, then they are deep-equal if and only if their string-values are equal.

If the two nodes are both object nodes, then they are deep-equal if and only if all of the following conditions are satisfied:

1. the two nodes have the same number of children, and the children have the same set of keys.
2. two children of the two nodes with the same key are deep-equal.
3. the order of children does not matter.

If the two nodes are both boolean nodes, then they are deep-equal if and only if their keys and boolean values are equal.

If the two nodes are both number nodes, then they are deep-equal if and only if their keys and values are equal.

If the two nodes are both null nodes, they are deep-equal.

Notes:

The two nodes are not required to have the same type annotation, and they are not required to have the same in-scope namespaces. They may also differ in their parent, their base URI, and the values returned by the is-id and is-idrefs accessors (see Section 5.5 is-id Accessor[DM] and Section 5.6 is-idrefs Accessor[DM]). The order of children is significant, but the order of attributes is insignificant.

The following note applies to the Jan 2007 XQuery specification, but not to the May 2003 XQuery specification: The contents of comments and processing instructions are significant only if these nodes appear directly as items in the two sequences being compared. The content of a comment or processing instruction that appears as a descendant of an item in one of the sequences being compared does not affect the result. However, the presence of a comment or processing instruction, if it causes a text node to be split into two text nodes, may affect the result.

The result of fn:deep-equal(1, current-dateTime()) is false; it does not raise an error.

Parameters
parameter1 The first sequence of items, each item should be an atomic value or node. If you pass in a single value, it is treated as a Sequence with that single item; therefore, if you pass in an array, the array is treated as a single value (not as one value for each item in the array). If you mean to pass in the values of each item in the array, then you can call xdmp.arrayValues on the array.
parameter2 The sequence of items to compare to the first sequence of items, again each item should be an atomic value or node. If you pass in a single value, it is treated as a Sequence with that single item; therefore, if you pass in an array, the array is treated as a single value (not as one value for each item in the array). If you mean to pass in the values of each item in the array, then you can call xdmp.arrayValues on the array.
collation The optional name of a valid collation URI. For information on the collation URI syntax, see the Search Developer's Guide.

Example

```const at = xdmp.unquote("<attendees> \
<name last='Parker' first='Peter'/> \
<name last='Barker' first='Bob'/> \
<name last='Parker' first='Peter'/> \
</attendees>")
fn.deepEqual(at, node);
=> false

const at = xdmp.unquote("<attendees> \
<name last='Parker' first='Peter'/> \
<name last='Barker' first='Bob'/> \
<name last='Parker' first='Peter'/> \
</attendees>")
=> false

const at = xdmp.unquote("<attendees> \
<name last='Parker' first='Peter'/> \
<name last='Barker' first='Bob'/> \
<name last='Parker' first='Peter'/> \
</attendees>")