|
* Retrieve an XML representation of the English Wikipedia main HTML page with whitespace stripped:
<syntaxhighlight pre lang="'xquery"'>
fetch:doc("http://en.wikipedia.org", map { 'stripws': true() })
</pre>
* Return a web page as XML, preserve namespaces:
<syntaxhighlight pre lang="'xquery"'>
fetch:doc(
'http://basex.org/',
|
* Retrieves file input as binary data and parses it as XML:
<syntaxhighlight pre lang="'xquery"'>
fetch:binary-doc(file:read-binary('doc.xml'))
</pre>
* Encodes a string as CP1252 and parses it as XML. The input and the string {{Code|touché}} will be correctly decoded because of the XML declaration:
<syntaxhighlight pre lang="'xquery"'>
fetch:binary-doc(convert:string-to-base64(
"<?xml version='1.0' encoding='CP1252'?><xml>touché</xml>",
</pre>
* Encodes a string as UTF-16 and parses it as XML. The document will be correctly decoded, as the first bytes of the data indicate that the input must be UTF-16:
<syntaxhighlight pre lang="'xquery"'>
fetch:binary-doc(convert:string-to-base64("<xml/>", "UTF16"))
</pre>