0

s9api.XdmValues don't seem to support obvious comparison methods - no equals() or hashCode().

Is this because directly comparing XDM sequences makes no sense for implementation reasons (some sequences may be lazy and of indeterminate size), or because the assumption is that if you want to compare two sequences, you should actually just compare the contents item-by-item? Is there a difference between Java equality and the equality test in XPath's fn:deep-equal() that has a bearing on this?

1 Answer 1

1

The various XML specifications provide quite a choice of methods for comparing equality; for example XSD has two separate notions ("equality" and "identity"), and XPath has different definitions for the eq operator, for distinct-values(), and for comparing keys in maps. That's just for comparing atomic values; for nodes it gets worse. There's the definition used by deep-equal() in XPath, there's the "is" operator in XPath, and there's equality under XML canonicalisation. The saxon:deep-equal() extends this further, with options to say whether (for example) whitespace text nodes, namespace prefixes, and comments are considered significant when comparing.

Most of these options are available form the Java API by some mechanism, but first you have to decide which one you want.

2
  • That makes sense - so generic comparison for sequences is not an agreed thing outside of those contexts within XPath or Canonicalisation where a specific definition exists. Fun! I was asking as the implementor of a wrapper library in another JVM hosted language, so I need to figure out if there's a concept of equality that makes idiomatic sense in that language and is one of the methods I can get access to... Thanks again.
    – fidothe
    Apr 1, 2019 at 10:29
  • Some of the decisions you need to make: (a) can a double ever be equal to an integer? (b) can two dates be equal if they are in different timezones, (c) are you happy to adopt the definition of fn:deep-equal() for comparing nodes? It's also worth noting that the XPath "=" operator is non-transitive, which makes it unsuitable for use in a framework where equals() is used in maps, sets, etc. Apr 1, 2019 at 11:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.