The xdmp:node-replace() call works against nodes in the database. By doing the xdmp:eval() you're passing in a node which has been essentially decoupled from its database context, thus the error message. If you pass a simple XPath as the first argument, it'll work for you.
Now, that's assuming you want to change the database not just change the document in memory. If you want to change a document in memory there's the in-mem-update library. It's open source XQuery code on developer.marklogic.com and also ships with recent versions of the server. -jh- On Apr 21, 2011, at 10:56 AM, Suganthi Srinivasan wrote: > I am trying to do a node replace in a document of a specified URI and > specified xpath expression. > > Tried to do eval to get old-element based on the passed in uri and xpath > expression. > But now xdmp:node-replace was giving error saying it cann't update external > node. > > The other way of getting the old-element is by $docRoot/xdmp:value($xpath), > but this gives me error: Prefix has no namespace binding, > obviously there are 3-4 namespace prefix for the given xpath, not sure how to > include those name-space bindings. > > > > xquery version "1.0-ml"; > > declare namespace xh = "http://www.w3.org/1999/xhtml"; > declare namespace pam = "http://prismstandard.org/namespaces/pam/2.0/"; > declare namespace prism = "http://prismstandard.org/namespaces/basic/2.1/"; > declare namespace dc="http://purl.org/dc/elements/1.1/"; > > declare variable $tempURI := "/temp/a001.xml"; > declare variable $xpath := "/pam:msg/pam:article/xh:head/dc:title"; > declare variable $new-value := "Schools, some state agencies closed"; > > > try { > > let $command := fn:concat(' > declare namespace pam="http://prismstandard.org/namespaces/pam/2.0/"; > declare namespace prism="http://prismstandard.org/namespaces/basic/2.1/"; > declare namespace dc="http://purl.org/dc/elements/1.1/"; > declare namespace xh="http://www.w3.org/1999/xhtml"; > fn:doc("',$tempURI ,'")',$xpath) > > let $old-element := xdmp:eval($command) > let $new-element := element {fn:node-name($old-element)} { > $old-element/@*, > $new-value} > return xdmp:node-replace($old-element, $new-element) > > } catch($e){ > xdmp:log($e),fn:concat("Problem editing the Temporary document node text : > error: ",$e/error:message/text()) > } > > Let me know if any one got any insights to this problem > Thanks, > Sugan > > _______________________________________________ > General mailing list > [email protected] > http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________ General mailing list [email protected] http://developer.marklogic.com/mailman/listinfo/general
