XQuery update in Basex GUI
Sunday, 10 May 2026 · 5 messages · last reply 11 May 2026
BE
Ben Engbers10 May 2026 00:52 #
Hi,
While improving my C++ test application for the libBasexCpp library, I tried to execute this line:
update insert <Line_1 line="1">Content 1</Line_1> into
doc('/TestCppClient/Test.xml')/root
This resulted in a crash. And since I only know the basics from XQuery, I wanted to use the GUI for debugging this instruction.
Even in the GUI this line could not be executed.
I consulted Mistral/leChat and it came to the conclusion that probably I haven't enabled the XQuery Update facility. But in the GUI I don't see how I could enable the update facility.
I am using linux/Fedora with standard open-jdk. Should I install additional jar-files?
Ben
--
Ben Engbers
Grietjeshof 77
6721 VH Bennekom
+31 6 23634840
GS
Graydon Saunders10 May 2026 01:13 #
If you're trying to change the actual thing, isn't the syntax going to be
insert node <Line_1 line="1">Content 1</Line_1> into
doc('/TestCppClient/Test.xml')/root
? If it's update (= do this in memory), I'd expect
return update {insert node <Line_1 line="1">Content 1</Line_1> into
doc('/TestCppClient/Test.xml')/root }because update always has expression braces for the change that gets applied as the update.
I also have the impression (https://docs.basex.org/main/Updates#update doesn't quite say explicitly) that `update` has a LHS so the processor knows what to copy when it applies the in-memory updates.
-- Graydon
Quoted text · Ben Engbers · 28 lines
On Sat, May 9, 2026, at 18:52, Ben Engbers via BaseX-Talk wrote: > Hi, > > While improving my C++ test application for the libBasexCpp library, I > tried to execute this line: > update insert <Line_1 line="1">Content 1</Line_1> into > doc('/TestCppClient/Test.xml')/root > > This resulted in a crash. And since I only know the basics from XQuery, > I wanted to use the GUI for debugging this instruction. > Even in the GUI this line could not be executed. > > I consulted Mistral/leChat and it came to the conclusion that probably I > haven't enabled the XQuery Update facility. But in the GUI I don't see > how I could enable the update facility. > > I am using linux/Fedora with standard open-jdk. Should I install > additional jar-files? > > Ben > > -- > Ben Engbers > Grietjeshof 77 > 6721 VH Bennekom > +31 6 23634840 > >
MH
Quoted text · Ben Engbers · 17 lines
On 10/05/2026 00:52, Ben Engbers via BaseX-Talk wrote: > Hi, > > While improving my C++ test application for the libBasexCpp library, I > tried to execute this line: > update insert <Line_1 line="1">Content 1</Line_1> into > doc('/TestCppClient/Test.xml')/root > > This resulted in a crash. And since I only know the basics from > XQuery, I wanted to use the GUI for debugging this instruction. > Even in the GUI this line could not be executed. > > I consulted Mistral/leChat and it came to the conclusion that probably > I haven't enabled the XQuery Update facility. But in the GUI I don't > see how I could enable the update facility. > >
Reading https://docs.basex.org/main/Updates#original_files might help:
In BaseX, all updates are performed on database nodes or in main memory. By default, update operations do not affect the original input file (the info string “Updates are not written back” is output to indicate this). The following solutions exist to write XML documents and binary resources to disk:
* Updates on main-memory instances of files that have been retrieved via|fn:doc|or|fn:collection|will be propagated back to disk if|WRITEBACK <https://docs.basex.org/main/Options#writeback>|is turned on. This option can also be activated oncommand line <https://docs.basex.org/main/Command-Line_Options#standalone>via|-u|. Make sure you back up the original documents before running your queries.
* Functions like|fn:put|or|file:write
<https://docs.basex.org/main/File_Functions#file:write>|can be used to write single XML documents to disk. With|
file:write-binary <https://docs.basex.org/main/File_Functions#file:write-binary>|, you can write binary resources.BE
Hi,
When using my library, these lines of code inserts the XML in the testdatabase:
Session.Add("Test.xml", "<root/>");
Session.Command("set mixupdates true");
Q_Object = Session.Query(
"insert nodes (<Line_1 line='1'>Content 1</Line_1>, <Line_2 line='2'>Content 2</Line_2>) "
"into doc('/TestCppClient/Test.xml')/root");
Q_Object -> Execute();
First problem solved! But a new problem was introduced.
I use the 'Full' command to return the reslts from a query.
Q_Object = Session.Query("'/TestCppClient/Test.xml'");
Q_Object -> Full();
cout << Session.getResultString();
==.<Line_1 line="1">Content 1</Line_1>But when I inspect the response from the server when executing the query with the 'Full' command, I can see that it contains the following content: /TestCppClient/Test.xml�|<Line_1 line="1">Content 1</Line_1>| /TestCppClient/Test.xml�|<Line_2 line="2">Content 2</Line_2>||| The '|' are inserted by my debug_dump function. A second function splits the original vector of bytes into a vector of vector of bytes. The '/TestCppClient/Test.xml' parts are elements 0,2, .. of the splitted vector.
|<Line_1 line="1">Content 1</Line_1>| is element 1.
It will be no big problem to adjust my code to get the correct output. But I wonder if the result from the server is in accordance with the documentation for the client server protocol (XDM {item} ... XDM {item} \00).
Is the byte in front of |<Line_1 the XDM metadata?
Ben
Quoted text · Graydon Saunders · 20 lines
Op 10-05-2026 om 01:13 schreef Graydon Saunders via BaseX-Talk: > If you're trying to change the actual thing, isn't the syntax going to be > > insert node <Line_1 line="1">Content 1</Line_1> into > doc('/TestCppClient/Test.xml')/root > > ? If it's update (= do this in memory), I'd expect > > return update {insert node <Line_1 line="1">Content 1</Line_1> into > doc('/TestCppClient/Test.xml')/root } > > because update always has expression braces for the change that gets > applied as the update. > > I also have the impression (https://docs.basex.org/main/Updates#update > <https://docs.basex.org/main/Updates#update> doesn't quite say > explicitly) that `update` has a LHS so the processor knows what to copy > when it applies the in-memory updates. > > -- Graydon
BE
Ben Engbers11 May 2026 14:43 #
In the documentation for XQJ I read that the Full command is used only for the XQJ api as provided by charles Foster and that the use is restricted to XQuery 3.0
Wouldn't it be better to just skip this command. If not, I will code that the Full command returns the server response (with the \ff bytes deleted).
Ben
Quoted text · Ben Engbers · 39 lines
Op 10-05-2026 om 22:18 schreef Ben Engbers via BaseX-Talk: > Hi, > > When using my library, these lines of code inserts the XML in the > testdatabase: > Session.Add("Test.xml", "<root/>"); > Session.Command("set mixupdates true"); > Q_Object = Session.Query( > "insert nodes (<Line_1 line='1'>Content 1</Line_1>, <Line_2 > line='2'>Content 2</Line_2>) " > "into doc('/TestCppClient/Test.xml')/root"); > Q_Object -> Execute(); > > First problem solved! But a new problem was introduced. > > I use the 'Full' command to return the reslts from a query. > Q_Object = Session.Query("'/TestCppClient/Test.xml'"); > Q_Object -> Full(); > cout << Session.getResultString(); > ==.<Line_1 line="1">Content 1</Line_1> > > > But when I inspect the response from the server when executing the query > with the 'Full' command, I can see that it contains the following content: > /TestCppClient/Test.xml�|<Line_1 line="1">Content 1</Line_1>| > /TestCppClient/Test.xml�|<Line_2 line="2">Content 2</Line_2>||| > The '|' are inserted by my debug_dump function. A second function splits > the original vector of bytes into a vector of vector of bytes. > The '/TestCppClient/Test.xml' parts are elements 0,2, .. of the splitted > vector. > |<Line_1 line="1">Content 1</Line_1>| is element 1. > > It will be no big problem to adjust my code to get the correct output. > But I wonder if the result from the server is in accordance with the > documentation for the client server protocol (XDM {item} ... XDM {item} > \00). > Is the byte in front of |<Line_1 the XDM metadata? > > Ben
Written for BaseX 12.3. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery