Changes

Jump to navigation Jump to search
301 bytes added ,  11:59, 16 December 2010
no edit summary
====insert====
<preclass="brush:xquery">
insert node (attribute {'a'} {5}, 'text', <e/>) as first into /n
</pre>
====delete====
<preclass="brush:xquery">
delete node //node
</pre>
====replace====
<preclass="brush:xquery">
replace node /n with <a/>
</pre>
The target element is replaced by the DOM node <a/>. You can also replace the value of a node or its descendants by using the modifier '''value of'''.
<preclass="brush:xquery">
replace value of node /n with (<a><b/></a>)
</pre>
====rename====
<preclass="brush:xquery">
for $n in //node
return rename node $n as 'renamedNode'
====transform====
<preclass="brush:xquery">
copy $c := doc('/doc.xml')//node[@id=1]
modify rename node $c as 'copyOfNode'
I we have the document:
<preclass="brush:xml">
<doc> <a/> </doc>
</pre>
... and perform the following query:
<preclass="brush:xquery">
insert node <b/> into /doc,
for $n in /doc/child::node()
The document looks like this:
<preclass="brush:xml">
<doc> <justRenamed/><b/> </doc>
</pre>
To use updating expressions within a function, the 'updating' flag has to be added to the function declaration. A correct declaration of a function that contains updating expressions (or one that calls updating functions) looks like this:
<preclass="brush:xquery">
declare updating function { ... }
</pre>
;DOM node as target:
:<preclass="brush:xquery">insert node attribute id{'1'} into <a id='0'/></pre>
:Result: <pre/>
;database node as target:
:File 'doc.xml': <preclass="brush:xml"><n id='1'/></pre>:<preclass="brush:xquery">insert node attribute id{'0'} into doc('doc.xml')//n</pre>
:Result: <pre style='color:red'>[XUDY0021] Duplicate attribute "id".</pre>
;Serializing a modified DOM node:
:Query:
<preclass="brush:xquery">
put(
copy $node := <n/>
modify insert node <x/> into $node
return $node , 'doc.xml')
</pre>
:file 'doc.xml':
<preclass="brush:xml">
<n><x/></n>
</pre>
[[Category:XQuery]]
[[Category:Finish]]
bueraucrat, Bureaucrats, editor, reviewer, Administrators
907

edits

Navigation menu