You may also want to copy the properties of the document and the properties
object itself.
A full rename is a little complex.
Here's the query I use to implement rename in the xmlsh MarkLogic extension ...
I got most of this off an older post -
I am not 100% sure its completely correct but it does appear to work.
-------------------- rename.xquery
xquery version "1.0-ml";
declare variable $src as xs:string external ;
declare variable $target as xs:string external ;
declare function local:document-rename(
$old-uri as xs:string, $new-uri as xs:string)
as empty-sequence()
{
xdmp:document-delete($old-uri)
,
let $permissions := xdmp:document-get-permissions($old-uri)
let $collections := xdmp:document-get-collections($old-uri)
return xdmp:document-insert(
$new-uri, doc($old-uri),
if ($permissions) then $permissions
else xdmp:default-permissions(),
if ($collections) then $collections
else xdmp:default-collections(),
xdmp:document-get-quality($old-uri)
)
,
let $prop-ns := namespace-uri(<prop:properties/>)
let $properties :=
xdmp:document-properties($old-uri)/node()
[ namespace-uri(.) ne $prop-ns ]
return xdmp:document-set-properties($new-uri, $properties)
};
local:document-rename($src,$target)
----------------------------------------
David A. Lee
Senior Principal Software Engineer
Epocrates, Inc.
[email protected]<mailto:[email protected]>
812-482-5224
From: [email protected]
[mailto:[email protected]] On Behalf Of Abhishek53 S
Sent: Tuesday, June 28, 2011 7:58 AM
To: General MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] Renaming a document
Hi Ambike,
It is not possible to update the URI of the document. For that you need to get
the content of existing and then insert the content with new document-uri and
then delete the older content.
Regards
Abhishek Srivastav
Systems Engineer
Tata Consultancy Services
Cell:- +91-9883389968
Mailto: [email protected]
Website: http://www.tcs.com<http://www.tcs.com/>
____________________________________________
Experience certainty. IT Services
Business Solutions
Outsourcing
____________________________________________
From:
ambika arumugam <[email protected]>
To:
General MarkLogic Developer Discussion <[email protected]>
Date:
06/28/2011 05:20 PM
Subject:
[MarkLogic Dev General] Renaming a document
Sent by:
[email protected]
________________________________
Hi all,
Is it possible in Marklogic to rename a document without really deleting the
old document and then inserting the document with the required document name?
Regards
Ambika_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general
=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain
confidential or privileged information. If you are
not the intended recipient, any dissemination, use,
review, distribution, printing or copying of the
information contained in this e-mail message
and/or attachments to it are strictly prohibited. If
you have received this communication in error,
please notify us by reply e-mail or telephone and
immediately and permanently delete the message
and any attachments. Thank you
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general