I would like to write a generic rename document function for MarkLogic.

I found this reference :

http://xqzone.marklogic.com/pipermail/general/2009-January/002297.html

 

But I am confused about it. Here's the suggested function:

 

 

------------

declare function local:document-rename($uri as xs:string)

  as empty-sequence()

{

   xdmp:document-delete($uri),

   let $permissions := xdmp:document-get-permissions($uri)

   let $collections := xdmp:document-get-collections($uri)

   let $quality := xdmp:document-get-quality($uri)

   return xdmp:document-insert(

     $uri, doc($uri),

     if ($permissions) then $permissions else
xdmp:default-permissions(),

     if ($collections) then $collections else
xdmp:default-collections(),

     $quality

   ),

   let $prop-ns := namespace-uri(<prop:properties/>)

   let $properties :=

     xdmp:document-properties($uri)/node()

       [ namespace-uri(.) ne $prop-ns ]

   return xdmp:document-set-properties($uri, $properties)

};

 

 

 

What confuses me ..

 

1)      it takes 1 arguement, which seems to be used as both the source
and target

2)      The document is deleted, then referenced 5 lines later - how is
this so ? ( maybe this is because the xdmp:document-delete() doesnt
operate until the function completes ?

3)      It appears that the document is re-inserted back into its same
name ... 

 

I *must* be missing something fundimental here, but I dont see how to
pass in both the old name and the new name.

something like :

                local:document-rename( "old.xml" , "new.xml" );

 

 

 

 

 

 

 

----------------------------------------

David A. Lee

Senior Principal Software Engineer

Epocrates, Inc.

[email protected] <mailto:[email protected]> 

812-482-5224

 

 

_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general

Reply via email to