Lee,

You're correct. I wasn't thinking very clearly when I posted that - sorry. Try this one:

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)
};

-- Mike

On 2009-11-08 12:51, Lee, David wrote:
Even though I dont understand it I gave it a shot and ran this xquery on an 
existing document “build.xml” and get this exception:

My *guess* is that the delete and insert are not co-existing happily.


com.marklogic.xcc.exceptions.XQueryException: XDMP-CONFLICTINGUPDATES: xdmp:document-insert("build.xml", 
doc("build.xml"), (), (), 0) -- Conflicting updates xdmp:document-insert("build.xml", 
doc("build.xml"), (), (), 0) and xdmp:document-delete("build.xml")
in /eval, on line 10
expr: xdmp:document-insert("build.xml", doc("build.xml"), (), (), 0),
in local:document-rename("build.xml")
in /eval, on line 22
expr: xdmp:document-insert("build.xml", doc("build.xml"), (), (), 0)






From: [email protected] 
[mailto:[email protected]] On Behalf Of Lee, David
Sent: Sunday, November 08, 2009 10:57 AM
To: [email protected]
Subject: [MarkLogic Dev General] Renaming Documents - question on example

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