when I bind a DOM tree as the context item in XQJ against an XQuery script that performs updates, the passed DOM tree is not modified.
Exactly – the tree is only modified within BaseX, but not converted back to the original DOM representation. You might be more successful with a transform/copy expression:
copy $c := . modify (insert node <x/> into $c, .....) return $c
Hope this helps, Christian
Here is a groovy
example import groovy.xml.XmlUtil import groovy.xml.DOMBuilder import groovy.xml.dom.DOMCategory import javax.xml.xquery.XQConstants docbuilder = DOMBuilder.newInstance() doc = docbuilder.sample() { renameMe(id:11) { renameInner(isit:"true","yes") } deleteMe(id:12) { alongWithMe("bummer") } insertBeforeMe(id:14) { alongWith(me:"true","Oh Yeah") andMe(too:"yes","Oh Yeah") } insertAfterMe(id:15) { atLevelThree(level:3) { atLevelFour(level:4, "fourth level") atLevelFour(level:4, "fourth level again") } alongWith(me:"true","Oh Yeah") } } // prints the DOM tree before updates XmlUtil.serialize(doc, System.out) ds = Class.forName("org.basex.api.xqj.BXQDataSource").newInstance() cnn = ds.getConnection() stmt = """ let $r := . return ( rename node $r/renameMe as 'gotRenamed', delete node $r/deleteMe[@id='12'], insert node <gotInsertedBefore id='13'> <alongWithMe>Cool</alongWithMe> </gotInsertedBefore> before $r/insertBeforeMe[@id='14'], insert node <gotInsertedAfter id='16'> <alongWithMe>Cool</alongWithMe> </gotInsertedAfter> after $r/insertAfterMe[@id='15'] ) """ xe = cnn.prepareExpression(stmt) xe.bindNode(XQConstants.CONTEXT_ITEM, doc, null) xqs = xe.executeQuery() // the DOM tree was not modified XmlUtil.serialize(doc, System.out) xqs.close() xe.close() cnn.close() Should I pass it as an external variable instead? Ciao Stefano _______________________________________________ BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk