[xquery-talk] Hashes

Liam Quin liam at w3.org
Wed Sep 20 21:31:37 PDT 2006

On Wed, Sep 20, 2006 at 04:09:33PM -0400, Tim Finney wrote:
> Sometimes I wish that XQuery had hashes:
> Clunky XQuery 1.0 way:
> if ($n = "a") then "aardvark"
> else if ($n = "b") then "bandicoot"

As others have said, use XML to store structured data,

let $hash := <hash>
  <value key="a">aardvark</value>
  <value key="b">bandicoot</value>

and then,
    $hash/hash/value[@key = "a"]

I always thought that XQuery should use this sort of thing for dates --
$date/month, and so forth -- and that this would encourage implementations
to do some smarter optimization for the case when people used XML to
hold values in this way.  But oh well... maybe one day :-)


Liam Quin, W3C XML Activity Lead, http://www.w3.org/People/Quin/
http://www.holoweb.net/~liam/ * http://www.fromoldbooks.org/

More information about the talk mailing list