Actions
Support #6454
open![Author: Haoyu Wang](https://www.gravatar.com/avatar/1db87e761a29d542bd4ce397444301cb?rating=PG&size=50&default=https%3A%2F%2Fassets.plan.io%2Fimages%2Fdefault_avatar.png)
java.lang.IllegalStateException: Query is updating
Status:
New
Priority:
Normal
Assignee:
-
Category:
-
Sprint/Milestone:
-
Start date:
2024-06-19
Due date:
% Done:
0%
Estimated time:
Legacy ID:
Applies to branch:
Fix Committed on Branch:
Fixed in Maintenance Release:
Platforms:
Description
How to run the following xquery?
public static void main(String[] args) {
System.setProperty("saxon.license", "/Users/haoyu/SMU/llm4pte-rust/engine/saxon-license.lic");
try {
Processor processor = new Processor(true); // Pass 'true' for licensed features
processor.setConfigurationProperty("http://saxon.sf.net/feature/licenseFileLocation", "/Users/haoyu/SMU/llm4pte-rust/engine/saxon-license.lic");
XQueryCompiler compiler = processor.newXQueryCompiler();
compiler.setUpdatingEnabled(true);
XQueryExecutable executable = compiler.compile(
"""
xquery version "3.1";
declare context item := document {
<library>
<book id="1">
<title>Programming Rust</title>
<author>Jim Blandy</author>
<price>39.99</price>
</book>
<book id="2">
<title>Learning Python</title>
<author>Mark Lutz</author>
<price>44.99</price>
</book>
</library>
};
(: Update the price of the first book :)
replace value of node /library/book[@id='1']/price with '34.99',
(: Insert a new book into the library :)
insert node\s
<book id="3">
<title>Effective Java</title>
<author>Joshua Bloch</author>
<price>45.99</price>
</book>
into /library,
(: Delete the second book from the library :)
delete node /library/book[@id='2']
(: Return the modified document :)
/library
"""
);
XQueryEvaluator evaluator = executable.load();
Serializer out = processor.newSerializer(System.out);
// out.setOutputProperty(Serializer.Property.METHOD, "xml"); // out.setOutputProperty(Serializer.Property.INDENT, "yes");
evaluator.run(out);
} catch (SaxonApiException e) {
e.printStackTrace();
}
}
Exception in thread "main" java.lang.IllegalStateException: Query is updating at net.sf.saxon.s9api.XQueryEvaluator.run(XQueryEvaluator.java:462) at XQueryUpdateExample.main(XQueryUpdateExample.java:56)
Updated by Michael Kay 26 days ago
An updating query doesn't return a result, so you need to call run()
without a destination argument. When the query has run, you can retrieve all updated documents using the getUpdatedDocuments()
method.
Please register to edit this issue
Actions