<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/fn.deepEqual.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>fn.deepEqual</api:function-name><api:suggest>fn.deepequal</api:suggest><api:suggest>fn</api:suggest><api:suggest>deepequal</api:suggest><api:function-link mode="xquery" fullname="fn:deep-equal">/apidoc/8.0/fn:deep-equal.xml</api:function-link><api:function mode="javascript" name="deepEqual" type="builtin" lib="fn" category="SequenceBuiltins" bucket="W3C-Standard Functions" hidden="false" prefix="fn" namespace="http://www.w3.org/2005/xpath-functions" fullname="fn.deepEqual"><api:summary>
<p xmlns="http://www.w3.org/1999/xhtml">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.
</p>
<p xmlns="http://www.w3.org/1999/xhtml">If the two sequences are both empty, the function returns true.
</p><p xmlns="http://www.w3.org/1999/xhtml">
If the two sequences are of different lengths, the function returns false.
</p><p xmlns="http://www.w3.org/1999/xhtml">
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.
</p><p xmlns="http://www.w3.org/1999/xhtml">
Call the two items $i1 and $i2 respectively.
</p><p xmlns="http://www.w3.org/1999/xhtml">
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.
</p><p xmlns="http://www.w3.org/1999/xhtml">
If one of the pair $i1 or $i2 is an atomic value and the other is a node, the
function returns false.
</p><p xmlns="http://www.w3.org/1999/xhtml">
If $i1 and $i2 are both nodes, they are compared as described below:
</p><p xmlns="http://www.w3.org/1999/xhtml">
If the two nodes are of different kinds, the result is false.
</p><p xmlns="http://www.w3.org/1999/xhtml">
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()).
</p><p xmlns="http://www.w3.org/1999/xhtml">
If the two nodes are both element nodes then they are deep-equal if and only if
all of the following conditions are satisfied:
</p>
<ol xmlns="http://www.w3.org/1999/xhtml"><li>the two nodes have the same name, that is (node-name($i1) eq
  node-name($i2)).</li><li>the two nodes are both annotated as having simple content or both nodes
  are annotated as having complex content.</li><li>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. </li><li>One of the following conditions holds:
    <ul><li>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. </li><li>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. </li><li>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()). </li><li>Both element nodes have a type annotation that is complex content with
    empty content. </li></ul>
  </li></ol>
<p xmlns="http://www.w3.org/1999/xhtml">
If the two nodes are both attribute nodes then they are deep-equal if and only
if both the following conditions are satisfied:
</p>
<ol xmlns="http://www.w3.org/1999/xhtml"><li>the two nodes have the same name, that is (node-name($i1) eq
  node-name($i2)).</li><li>the typed value of $i1 is deep-equal to the typed value of $i2.</li></ol>
<p xmlns="http://www.w3.org/1999/xhtml">
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:
</p>
<ol xmlns="http://www.w3.org/1999/xhtml"><li>the two nodes have the same name, that is (node-name($i1) eq
  node-name($i2)). </li><li>the string value of $i1 is equal to the string value of $i2.</li></ol>
<p xmlns="http://www.w3.org/1999/xhtml">
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.
</p><p xmlns="http://www.w3.org/1999/xhtml">
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.
</p><p xmlns="http://www.w3.org/1999/xhtml">
If the two nodes are both comment nodes, then they are deep-equal
if and only if their string-values are equal.
</p><p xmlns="http://www.w3.org/1999/xhtml">
If the two nodes are both object nodes, then they are deep-equal if and only if
all of the following conditions are satisfied:
</p>
<ol xmlns="http://www.w3.org/1999/xhtml"><li>the two nodes have the same number of children, and the children have the
    same set of keys.</li><li>two children of the two nodes with the same key are deep-equal.</li><li>the order of children does not matter. </li></ol>
<p xmlns="http://www.w3.org/1999/xhtml">
If the two nodes are both boolean nodes, then they are deep-equal
if and only if their keys and boolean values are equal.
</p><p xmlns="http://www.w3.org/1999/xhtml">
If the two nodes are both number nodes, then they are deep-equal
if and only if their keys and values are equal.
</p><p xmlns="http://www.w3.org/1999/xhtml">
If the two nodes are both null nodes, they are deep-equal.
</p><p xmlns="http://www.w3.org/1999/xhtml">
Notes:
</p><p xmlns="http://www.w3.org/1999/xhtml">
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.
</p><p xmlns="http://www.w3.org/1999/xhtml">
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.
</p><p xmlns="http://www.w3.org/1999/xhtml">
The result of fn:deep-equal(1, current-dateTime()) is false; it does not raise
an error.
</p>
</api:summary><api:params><api:param name="parameter1" type="item()*"><api:param-description>
  The first sequence of items, each item should be an atomic value or node.
  <span class="javascript" xmlns="http://www.w3.org/1999/xhtml">If you pass in a single value, 
  it is treated as a ValueIterator 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 
  <a href="./xdmp.arrayValues">xdmp.arrayValues</a> on the array. </span>
  </api:param-description><api:param-name>parameter1</api:param-name><api:param-type>ValueIterator</api:param-type></api:param><api:param name="parameter2" type="item()*"><api:param-description>
  The sequence of items to compare to the first sequence of items, again each
  item should be an atomic value or node.
  <span class="javascript" xmlns="http://www.w3.org/1999/xhtml">If you pass in a single value, 
  it is treated as a ValueIterator 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 
  <a href="./xdmp.arrayValues">xdmp.arrayValues</a> on the array. </span>
  </api:param-description><api:param-name>parameter2</api:param-name><api:param-type>ValueIterator</api:param-type></api:param><api:param name="collation" type="xs:string" optional="true"><api:param-description>
  The optional name of a valid collation URI.  For information on the
  collation URI syntax, see the <em xmlns="http://www.w3.org/1999/xhtml">Search Developer's Guide</em>.
  </api:param-description><api:param-name>collation</api:param-name><api:param-type>String</api:param-type></api:param></api:params><api:return>Boolean</api:return><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
var at = xdmp.unquote("&lt;attendees&gt; \
             &lt;name last='Parker' first='Peter'/&gt; \
             &lt;name last='Barker' first='Bob'/&gt; \
             &lt;name last='Parker' first='Peter'/&gt; \
           &lt;/attendees&gt;")
node = at.toArray()[0].xpath("./element()");
fn.deepEqual(at, node);
=&gt; false

var at = xdmp.unquote("&lt;attendees&gt; \
             &lt;name last='Parker' first='Peter'/&gt; \
             &lt;name last='Barker' first='Bob'/&gt; \
             &lt;name last='Parker' first='Peter'/&gt; \
           &lt;/attendees&gt;")
fn.deepEqual(at.toArray()[0].xpath("./attendees/name[1]"), 
	     at.toArray()[0].xpath("./attendees/name[2]"))
=&gt; false

var at = xdmp.unquote("&lt;attendees&gt; \
             &lt;name last='Parker' first='Peter'/&gt; \
             &lt;name last='Barker' first='Bob'/&gt; \
             &lt;name last='Parker' first='Peter'/&gt; \
           &lt;/attendees&gt;")
fn.deepEqual(at.toArray()[0].xpath("./attendees/name[1]"), 
	     at.toArray()[0].xpath("./attendees/name[3]"))
=&gt; true

var at = xdmp.unquote("&lt;attendees&gt; \
             &lt;name last='Parker' first='Peter'/&gt; \
             &lt;name last='Barker' first='Bob'/&gt; \
             &lt;name last='Parker' first='Peter'/&gt; \
           &lt;/attendees&gt;")
fn.deepEqual(at.toArray()[0].xpath("./attendees/name[1]"), 
	     "Peter Parker")
=&gt; false
</pre>
</api:example></api:function></api:function-page>