I made a simple XML called order.xml like this: -------------order.xml-------------- <orders> <order> <name>cola</name> <price>3.0</price> <factory>Number 1</factory> </order> <order> <name>coffee</name> <price>5.0</price> <factory>Number 2</factory> </order> </orders> --------------------------------------------
Now I want to update the price of the coffee to 6.0 with XQJ, so I got the following code:
String driverName = "org.basex.api.xqj.BXQDataSource"; Class<?> driverClass = Class.forName(driverName); XQDataSource dataSource = (XQDataSource)driverClass.newInstance(); XQConnection xqc = dataSource.getConnection();
String updateString = "declare variable $node := doc('etc/xml/orders.xml')//order[name='coffee']; "+ "replace value of node $node/price with '5.0', " + "return " + "put(doc('etc/xml/orders.xml'), 'orders.xml')"; XQExpression xqu = xqc.createExpression(); xqu.executeQuery(updateString); xqu.close();
unfortunately, it throws an exception. I tried many different ways and fails all the time. could any tell me the right "updateString"?
thanks a lot.
Dear Qu Xia,
i just checked your query and the problem was at the put function. I have rewritten it like this:
put (copy $doc := doc('orders.xml') modify replace value of node $doc//order[name='coffee']/price with '5.0' return $doc, 'orders.xml')
Maybe there are other solutions but this worked for me.
Kind regards, Andreas
Qu Xia schrieb:
I made a simple XML called order.xml like this: -------------order.xml--------------
<orders> <order> <name>cola</name> <price>3.0</price> <factory>Number 1</factory> </order> <order> <name>coffee</name> <price>5.0</price> <factory>Number 2</factory> </order> </orders> --------------------------------------------
Now I want to update the price of the coffee to 6.0 with XQJ, so I got the following code:
String driverName = "org.basex.api.xqj.BXQDataSource"; Class<?> driverClass = Class.forName(driverName); XQDataSource dataSource = (XQDataSource)driverClass.newInstance(); XQConnection xqc = dataSource.getConnection();
String updateString = "declare variable $node := doc('etc/xml/orders.xml')//order[name='coffee']; "+ "replace value of node $node/price with '5.0', " + "return " + "put(doc('etc/xml/orders.xml'), 'orders.xml')"; XQExpression xqu = xqc.createExpression(); xqu.executeQuery(updateString); xqu.close();
unfortunately, it throws an exception. I tried many different ways and fails all the time. could any tell me the right "updateString"?
thanks a lot.
-- Xia Qu Technology Center of Software Engineering, Institute of Software, Chinese Academy of Sciences Beijing, 100190, China Email (work):quxia08@otcaix.iscas.ac.cn mailto:quxia08@otcaix.iscas.ac.cn Email (personal): tsuxia@gmail.com mailto:tsuxia@gmail.com Mobile:(86) 1300-1010-069
BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
basex-talk@mailman.uni-konstanz.de