Hi,
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());
}
}