Hi Ingo,
as you correctly observed, we are using 'pre' values to organize nodes in our database, which will change after updates (see [1] for further details on pre and id values and the id/pre mapping). It is generally possible to use our DOM interface, but I’m inclined to recommend you the database functions db:open-pre() and db:node-pre(). If you perform updates, db:open-id() and db:node-id() and the UPDINDEX option will help you [2]. You could also work with the DBNode instances, which are returned by the query processor, as this will be much faster than using the DOM wrapper, but it may take more time to get acquainted with the internal node interface.
Regards, Christian
[1] http://docs.basex.org/wiki/Node_Storage#PRE_Value [2] http://docs.basex.org/wiki/Database_Module#db:open-pre ___________________________
I have a problem using BaseX Java DOM Node Interface and updating XQuerys in combination. The problem is that on updating the XML structure the node "pointer" moves to another location therefore the BXNode Object points to the wrong node. I have investigated a bit and the problem seems to be the 'pre' attribute in Class DBNode that points to the wrong/old location. There is already an uninque ID in ANode that could be used to identify the right node. But a ID->pre mapping table is missing. Any solution/workaround for this issue?
Best regards, Ingo
See following snippet that demonstrates the issue:
import java.io.ByteArrayInputStream; import org.basex.api.dom.BXNode; import org.basex.core.Context; import org.basex.core.Prop; import org.basex.core.cmd.CreateDB; import org.basex.core.cmd.Set; import org.basex.query.QueryProcessor; import org.basex.query.value.item.Item; import org.basex.query.value.node.ANode; public class UpdateAndDOM { public static void main(String[] args) throws Exception { // create test DB in memory Context context = new Context(); new Set(Prop.MAINMEM, true).execute(context); ByteArrayInputStream bais = new ByteArrayInputStream("<root><node1/></root>".getBytes()); CreateDB cmd = new CreateDB("testDB"); cmd.setInput(bais); cmd.execute(context); //get DOM node "node1" QueryProcessor query = new QueryProcessor("//node1", context); query.execute(); Item item = query.iter().next(); Object elem = BXNode.get((ANode)item); BXNode node1 = (BXNode)elem; System.out.println("Expected node1 is: " + node1.getNodeName()); //updating query that inserts data before node1 String xpath = "insert node <newNode/> before /root/node1"; query = new QueryProcessor(xpath, context); query.execute(); System.out.println("Expected node1 is: " + node1.getNodeName()); } }
BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk