[Fwd: Re: [XQZone General] Posting binary data - tricky?]

Nick Lanham nick at marklogic.com
Tue Aug 16 13:03:41 PDT 2005

as michael has rightly pointed out (see below), data() returns as
hexBinary not base64, my mistake.

the rest of the solution remains the same though, just decode/transform
from hexBinary (probably easier than from base64 anyway).


-----Forwarded Message-----
From: Michael Blakeley <michael.blakeley at marklogic.com>
To: nick at marklogic.com
Subject: Re: [XQZone General] Posting binary data - tricky?
Date: Tue, 16 Aug 2005 12:50:30 -0700

> it is a bit tricky yes.  the main problem with just trying to quote your
> binary data is that you might have (for example) null characters in it,
> making it difficult to turn into a string.
> an approach i've used is to turn the node into a base64 string of what
> you want to post like so (data() on a binary node will base64 encode):
> let $img := doc("foo.jpg")
> return 
>   xdmp:http-post("http://mywebservice:9000",
>     <options xmlns="xdmp:http">
>       <data>{data($img/node())}</data>
>     </options>);
> and then un-encode it on the other side.


I'm nitpicking, but data() seems to return a hexBinary, not a base64Binary.

let $img := binary { xs:hexBinary("deadbeef") }
    <options xmlns="xdmp:http">

<options xmlns="xdmp:http">

xdmp:describe(data(binary { xs:hexBinary("deadbeef") }))


I had to do this to achieve a round-trip:

let $b := binary { xs:hexBinary("deadbeef") }
let $encoded := xdmp:base64-encode(
  string(xs:hexBinary(binary { xs:hexBinary("deadbeef") }))
let $decoded := binary { xdmp:base64-decode($encoded) }
return $b eq $decoded


No idea to what extent those trips from hex to base64 are optimized, if
at all....

-- Mike

More information about the General mailing list