The other alternative is you can use simple xpath on the map document ... It may or may not be more efficient or easier, it depends.
For example if you have a very large map stored in the database and need only 1 key then using xpath to retrieve that one key could be faster than creating a map:map and getting the key. declare namespace map="http://marklogic.com/xdmp/map" ; fn:doc("map.xml")/map:map/map:entry[ @key eq "1"/map:value/fn:data(.) You can even set up range indexes on the key attributes and use cts:query on those ... particularly useful if you have many map documents. But in the case (likely) where you want a map:map back ... David's answer is best let $map := map:map(fn:doc("/map.xml")/node()) You now have a map:map you can do whatever mappy things you want with. ----------------------------------------------------------------------------- David Lee Lead Engineer MarkLogic Corporation [email protected] Phone: +1 812-482-5224 Cell: +1 812-630-7622 www.marklogic.com<http://www.marklogic.com/> From: [email protected] [mailto:[email protected]] On Behalf Of David Lam Sent: Wednesday, November 21, 2012 4:53 AM To: MarkLogic Developer Discussion Subject: Re: [MarkLogic Dev General] Xquery - Maps On Wed, Nov 21, 2012 at 1:25 AM, sini narayanan <[email protected]<mailto:[email protected]>> wrote: Hi MIke, Now that I have the xml file in my DB, how do I loop through the xml keys to get its corresponding values? <?xml version="1.0" encoding="UTF-8"?> <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="1"> <map:value xsi:type="xs:string">hello</map:value> </map:entry> <map:entry key="2"> <map:value xsi:type="xs:string">world</map:value> </map:entry> </map:map> You need to first initialize the map from the document, and iterate through the keys. map:map() returns an empty map by default! --> (: david definitely did not test the below at all :) let $map := map:map(fn:doc("/map.xml")/node()) for $key in map:keys($map) return <store-result key="{ $key }">{ map:get($map, $key) } </store-result> Tried the below code : Which is not returning any value xquery version "1.0-ml"; let $map := map:map() let $value := for $keys in fn:doc("/map.xml") return map:get($map,"1") return <store-result> <value>{$value}</value> </store-result> Please help. Thanks On Tue, Nov 20, 2012 at 7:06 PM, Michael Blakeley <[email protected]<mailto:[email protected]>> wrote: Use document { $map } to get the XML for the map. With that XML you can call xdmp:document-insert, etc. See http://docs.marklogic.com/guide/app-dev/hashtable especially http://docs.marklogic.com/guide/app-dev/hashtable#id_88528 -- Mike On 20 Nov 2012, at 09:18 , sini narayanan <[email protected]<mailto:[email protected]>> wrote: > Hi, > > I have a map to be created as below: > > let $map := map:map() > let $key := map:put($map, "1", "hello") > let $key := map:put($map, "2", "world") > return $map > > How do I store this as a file in MarkLogic DB? > What would be the format in which maps are saved ? > > I want to access this map from an xqy module which would pass the key as > input to the map file to get the output. > Please advice. > > Thanks > _______________________________________________ > General mailing list > [email protected]<mailto:[email protected]> > http://developer.marklogic.com/mailman/listinfo/general _______________________________________________ General mailing list [email protected]<mailto:[email protected]> http://developer.marklogic.com/mailman/listinfo/general _______________________________________________ General mailing list [email protected]<mailto:[email protected]> http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________ General mailing list [email protected] http://developer.marklogic.com/mailman/listinfo/general
