I think the issue is that the xdmp:eval call in your first let is run in
a separate context from the rest of the statement, so the
xdmp:node-replace does not have access to that context. If you want to
do something like this, you will need to construct a string to eval that
includes the whole statement, including your xdmp:node-replace.
Something like (I might have a syntax error here as I did not try and
run it):
let $new-node := <something to construct the new node as a string>
return
fn:concat('xdmp:node-replace(doc("', $uri, '")', $path, ', ' $new-node,
')')
-Danny
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Eric
Palmitesta
Sent: Monday, September 08, 2008 1:19 PM
To: General Mark Logic Developer Discussion
Subject: Re: [MarkLogic Dev General] update function
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
>> [email protected]
>> http://xqzone.com/mailman/listinfo/general
> _______________________________________________
> General mailing list
> [email protected]
> http://xqzone.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general