What's the problem
I am trying to get XQuery to work in VS Code using BaseX, but every time I try to execute a query using XML Tools, it fails because its execution in the command is returning an error code.
How do I know that is the problem?
On the repository for the extension it says:
The output of the execution engine is captured via the stdout for your operating system. If the process exits with any code other than 0, any content written to stdout is shown as an error message. If the content from stdout contains a line number, the error prompt will contain a button to take you to the line in question.
The result that I receive when I run my query is the exact query result written as an error, which is exactly what you'd expect given the quote above.
How am I configuring the settings.json
On the aforementioned repository, the settings.json
is written as follows:
{
"xmlTools.xqueryExecutionEngine": "C:\\Program Files (x86)\\Altova\\AltovaXML2008\\AltovaXML.exe",
"xmlTools.xqueryExecutionArguments": [
"-xquery", "$(script)",
"-in", "$(input)"
"-out", "$(input).output.xml"
]
}
But, I am using BaseX, so I tried to create the equivalent of the above using it:
"xmlTools.xqueryExecutionEngine": "basex.bat",
"xmlTools.xqueryExecutionArguments": [
"$(script)",
"-i", "$(input)",
"-o", "output.xml"
],
From the basex docs, this looks like the right execution idea.
Note:
- If output.xml doesn't already exist, Windows sends an error code 9009. To get around that, I just use a predefined file but if there's a way to avoid this problem and just create the file without an error, I'd love to know how.
- Writing the following
Alternate settings.json
"xmlTools.xqueryExecutionArguments": [
"-o", "output.xml",
"$(script)",
],
does not work, although that's the way I have to write it in the cmd (I have also tried this while including the input file, but as I don't use it in my particular case, I tried both ways).
What Works
In the cmd
, writing
basex -o output.xml data.xq
Works, and if output.xml
exists, then
echo %ErrorLevel%
returns 0
.
I am a bit confused on how settings.json
is translated to the cmd, so I'm not sure how to recreate the problem encountered in VS Code in my cmd. If there is a way to ignore exit codes (and prevent halting the execution of my command), that would resolve my problem. Even better would be to find the correct way to write to settings.json
that allows me to run my XQueries from VS Code.
Test data
For testing's sake, here are the files I use
data.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="personType">
<xs:sequence>
<xs:element name="fname" type="xs:string"/>
<xs:element name="minit" type="xs:string"/>
<xs:element name="lname" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="peopleType">
<xs:sequence>
<xs:element name="person" type="personType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:element name="peopleDB" type="peopleType"></xs:element>
</xs:schema>
data.xml
<?xml version="1.0" ?>
<peopleDB xsi:noNamespaceSchemaLocation="data.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<person>
<fname>John</fname>
<minit>A</minit>
<lname>Roger</lname>
</person>
<person>
<fname>Fred</fname>
<minit>X</minit>
<lname>Gerald</lname>
</person>
</peopleDB>
data.xq
<personDB>
{
let $d:=doc("data.xml") for $p in
$d/peopleDB/person
return $p
}
</personDB>