Note that there are some explanatory texts on larger screens.

plurals
  1. POXQuery fn:deep-equal - comparing text from XPath with string literal
    primarykey
    data
    text
    <p>I'm trying to use XQuery function <strong>fn:deep-equal</strong> to compare sections of XML documents and I'm getting unexpected behaviour. When comparing XPath value with string literal, function returns false. </p> <p>For example following code</p> <pre><code>let $doc := &lt;root&gt; &lt;child&gt;&lt;message&gt;Hello&lt;/message&gt;&lt;/child&gt; &lt;/root&gt; let $message := &lt;message&gt;Hello&lt;/message&gt; let $value := $doc/child/message/text() let $compareDirectly := fn:deep-equal($value, "Hello") (: -&gt; false :) let $compareAsString := fn:deep-equal(fn:concat($value, ""), "Hello") (: -&gt; true :) let $comparePath := fn:deep-equal($value, $message/text()) (: -&gt; true :) return &lt;results&gt; &lt;value&gt;{$value}&lt;/value&gt; &lt;directly&gt;{$compareDirectly}&lt;/directly&gt; &lt;asString&gt;{$compareAsString}&lt;/asString&gt; &lt;path&gt;{$comparePath}&lt;/path&gt; &lt;/results&gt; </code></pre> <p>Executed using Saxon, XQuery program generates following XML</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;results&gt; &lt;value&gt;Hello&lt;/value&gt; &lt;directly&gt;false&lt;/directly&gt; &lt;asString&gt;true&lt;/asString&gt; &lt;path&gt;true&lt;/path&gt; &lt;/results&gt; </code></pre> <p>I'd expect $compareDirectly to be true (same as two other examples), but fn:deep-equal does not seem to work as I would intuitively expect. I'm wondering whether this is correct behaviour.</p> <p>Is there any better wah how to compare two XML nodes?</p> <p>I'm lookig for some generic solution which could be used for both XML snippets (like values of $doc or $message in example) and also for this special case with string literal.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload