Index ¦ Archives ¦ Atom

Binary Upload in MarkLogic

For a project I'm working I needed to upload a PDF and a corresponding XML file. I also added functionality to upload zip files. The zip file would contain the pdf/xml file pairs, and for good measure I decided to allow for embedded zip files as well. The most difficult part of this was taking in binary content, storing the content in a map:map, and then getting the data back out again. I continually ran into errors like XDMP-CHILDNODEKIND: element nodes cannot have binary node children and XDMP-UTF8SEQ -- Invalid UTF-8 escape sequence. These errors were largely caused by my trying to xdmp:unquote and xdmp:quote the content to get the binary value to store in the map:map. I ended up doing this to store the value in the map:

xs:string(xs:hexBinary($binary-contents))

and when I need to store the value in the database I used:

binary { xs:hexBinary($mapvalue) }

This seems to work like a charm. All my weird xml parsing issues are gone.

© Steve Spigarelli. Built using Pelican. Theme by Giulio Fidente on github.