The map built-in functions are used to create maps. Maps store name-value pairs in an in-memory data structure. You can also persist a map to disk by storing it in a document. Some programming languages implement maps using hash tables, but these map functions make it convenient for you to create and update your own maps.
Maps are represented using the map:map XQuery primitive type. When you serialize an object of map:map type, it serializes to an XML node in the http://marklogic.com/xdmp/map namespace.
map:map
http://marklogic.com/xdmp/map
map:clear($table) => ()
map:contains($table, "some-key") => fn:true()
(: assume $table is bound to a map with 15 keys :) map:count($table) => 15
let $map := map:map() let $_map := map:put($map, "a", 1) let $_map := map:put($map, "a", 2) let $_map := map:put($map, "b", 1) let $_map := map:put($map, "b", 2) return ($map, map:count($map)) => map:map( <map:map xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:map="http://marklogic.com/xdmp/map"> <map:entry key="b"> <map:value xsi:type="xs:integer">2</map:value> </map:entry> <map:entry key="a"> <map:value xsi:type="xs:integer">2</map:value> </map:entry> </map:map>) 2
map:delete($table, "some-key") => ()
let $table := map:map() let $_ := map:put($table, "some-key", <info>45683</info>) return map:get($table, "some-key") => <info>45683</info>
map:keys($table) => ("some-key", "another key", "and another one")
map:map() => map:map(<map xmlns="http://marklogic.com/xdmp/map"/>)
xquery version "1.0-ml"; let $map := <map:map xmlns:map="http://marklogic.com/xdmp/map"> <map:entry key="2"> <map:value xsi:type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >world</map:value> </map:entry> <map:entry key="1"> <map:value xsi:type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >hello</map:value> </map:entry> </map:map> return map:get(map:map($map), "2") => world
let $map := map:map() let $put := map:put($map, "some-key", <info>45683</info>) return <result>{$map}</result> => <result> <map:map xmlns:map="http://marklogic.com/xdmp/map" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <map:entry key="some-key"> <map:value> <info>45683</info> </map:value> </map:entry> </map:map> </result>