This page was generated
August  8,  2011
2:23  AM
XQuery Built-In and Modules Function Reference

Built-In: map

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.

Function Summary
map:clear Clear a map.
map:count Returns the number of entries used in the map.
map:delete Delete a value from a map.
map:get Get a value from a map.
map:keys Get the keys used in the map.
map:map Creates a map.
map:put Put a value into a map at the given key.
Function Detail
map:clear(
$map as map:map
)  as   empty-sequence()
Summary:

Clear a map.

Parameters:
$map : A map.

Example:
  map:clear($table)
  => ()

map:count(
$map as map:map
)  as   xs:unsignedInt
Summary:

Returns the number of entries used in the map.

Parameters:
$map : A map.

Example:
  map:count($table)
  => 15

map:delete(
$map as map:map,
$key as xs:string
)  as   empty-sequence()
Summary:

Delete a value from a map.

Parameters:
$map : A map.
$key : A key.

Example:
  map:delete($table, "some-key")
  => ()

map:get(
$map as map:map,
$key as xs:string
)  as   item()*
Summary:

Get a value from a map.

Parameters:
$map : A map.
$key : A key.

Example:
  map:get($table, "some-key")
  => <info>45683</info>

map:keys(
$map as map:map
)  as   xs:string*
Summary:

Get the keys used in the map.

Parameters:
$map : A map.

Example:
  map:keys($table)
  => ("some-key", "another key", "and another one")

map:map(
[$map as element(map:map)]
)  as   map:map
Summary:

Creates a map.

Parameters:
$map (optional): A serialized map element.

Example:
  map:map()
  => map:map()

map:put(
$map as map:map,
$key as xs:string,
$value as item()*
)  as   empty-sequence()
Summary:

Put a value into a map at the given key.

Parameters:
$map : A map.
$key : A key. If the key is not unique, it will overwrite the existing key.
$value : A value. If the value is the empty sequence, it will remove the key from the map.

Example:
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">
    <map:entry>
      <map:key>some-key</map:key>
      <map:value><info>45683</info></map:value>
    </map:entry>
  </map:map>
</result>