fn.deepEqual( $parameter1 as Sequence, $parameter2 as Sequence, [$collation as String] ) as Boolean
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:
If the two nodes are both attribute nodes then they are deep-equal if and only if both the following conditions are satisfied:
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:
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:
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 accesors (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. |
const at = xdmp.unquote("<attendees> \ <name last='Parker' first='Peter'/> \ <name last='Barker' first='Bob'/> \ <name last='Parker' first='Peter'/> \ </attendees>") node = fn.head(at).xpath("./element()"); 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>") fn.deepEqual(fn.head(at).xpath("./attendees/name[1]"), fn.head(at).xpath("./attendees/name[2]")) => false const at = xdmp.unquote("<attendees> \ <name last='Parker' first='Peter'/> \ <name last='Barker' first='Bob'/> \ <name last='Parker' first='Peter'/> \ </attendees>") fn.deepEqual(fn.head(at).xpath("./attendees/name[1]"), fn.head(at).xpath("./attendees/name[3]")) => true const at = xdmp.unquote("<attendees> \ <name last='Parker' first='Peter'/> \ <name last='Barker' first='Bob'/> \ <name last='Parker' first='Peter'/> \ </attendees>") fn.deepEqual(fn.head(at).xpath("./attendees/name[1]"), "Peter Parker") => false
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.