XQuery/HelloWorld
Motivation
editYou want to run a small program that tests to see if your XQuery execution environment is working.
XML Output
editxquery version "1.0";
let $message := 'Hello World!'
return
<results>
<message>{$message}</message>
</results>
Expected Output
edit<results>
<message>Hello World!</message>
</results>
Discussion
editThe program creates a temporary variable called $message
and assigns it a string value. The output is an XML element containing a message element which contains the value of the variable.
Suggestions
editTry omitting the curly braces from inside of the result message element. What do you get? Execute
What happens if you omit the results wrappers? Execute
Plain Text
editYou can get XQuery to return plain text using serialization options which define the serialization and the output media-type.
For example to output the message as text, specify the serialization as text and the media-type as text/plain.
xquery version "1.0";
declare option exist:serialize "method=text media-type=text/plain";
let $message := 'Hello World!'
return
$message
Expected Output
editDepending on your browser set-up, this will launch a viewer for text documents and display
Hello World!