[MarkLogic Dev General] update function

Eric Palmitesta eric.palmitesta at utoronto.ca
Mon Sep 8 13:18:44 PDT 2008


Mike,

Just saw that, which covers the "Cannot update constructed nodes" error. 
  Switching that around still gives "Cannot update external nodes".

Eric

Mike Sokolov wrote:
> This one looks like a dopey typo:
> 
> xdmp:node-replace($new-node, $old-node)
> 
> should read
> 
> xdmp:node-replace($old-node, $new-node)
> 
> I think...
> 
> Eric Palmitesta wrote:
>> I'm putting together a function which updates a single element in an 
>> xml file, however I'm getting an error I'm not sure how to deal with.
>>
>> (WARNING, INCOMING EVAL)
>>
>> define function update($uri as xs:string, $path as xs:string, $value 
>> as item())
>> {
>>   let $old-node := xdmp:eval(concat('doc("', $uri, '")', $path))
>>   let $new-node := element { tokenize($path, "/")[last()] } { text { 
>> $value } }
>>   return
>>     xdmp:node-replace($new-node, $old-node)
>> }
>>
>> When I run something like:
>>
>> update('/path/to/file.xml', '/path/to/element', 'new value')
>>
>> $old-node should be doc("/path/to/file.xml")/path/to/element
>> $new-node should be <element>new value</element>
>>
>> I get:
>>
>> XDMP-UPCONSTNODES: Cannot update constructed nodes
>>
>>
>> What's strange is if I replace the $new-node and $old-node variables 
>> with their assigned values above, that same call gets me:
>>
>> XDMP-UPEXTNODES: Cannot update external nodes
>>
>> What am I missing here?
>>
>> Eric
>> _______________________________________________
>> General mailing list
>> General at developer.marklogic.com
>> http://xqzone.com/mailman/listinfo/general
> _______________________________________________
> General mailing list
> General at developer.marklogic.com
> http://xqzone.com/mailman/listinfo/general


More information about the General mailing list