XQuery/Special Characters
Contents |
Motivation [edit]
You want to control where you put special characters such as newlines and quote characters in your XML files.
Method [edit]
We will create XQuery variables (referents) to the decimal encoded character values using the &#NN' notation where NN is the decimal number for this character in the character set. We can then add these variables anywhere in the output stream.
Example Program [edit]
In this example we will create a variable $nl had have it refer to the newline character. We will then put this in the middle of a string.
xquery version "1.0"; let $nl := " " let $quote := """ let $string := concat("Hello", $nl, "World") return $string
Returns:
Hello World
The following shows how both quote and newline special characters can be created.
let $nl := " " let $quote := """ let $string := concat($quote, "Hello", $nl, "World", $quote) return $string
Returns:
"Hello World"
Note that the string length of these variables string-length($nl) and string-length($quote) is only one character.
Other Useful Escape Characters [edit]
let $open-curly := "{" (: for { :) let $closed-curly := "}" (: for } :) let $space := " " (: space :) let $tab := "	" (: tab :) let $ampersand := "&" (: ampersand :)
Reference
For other characters see the following table: