XQuery/XMP data

= Motivation = Adobe have introduced an XML format for image metadata called XMP. You want to display a photograph and some of the metadata.

= Background =

Matt Turner has an example of using MarkLogic to extract XMP data from a JPEG image.

= eXist/ XQuery implementation =

Here is the code using eXist XQuery extensions. Matt's photograph of a boat has been stored in the XML Database as a binary file.

= Show the full XMP XML =

The binary image is retrieved from the database as a BASE64 encoded string, converted to a UTF-8 string, the metadata text extracted and turned back to XML using util:parse

declare function local:extract-xmp ($jpeg as xs:string) as item { let $binary := util:binary-doc($jpeg) let $text := util:binary-to-string($binary) let $xmp := substring-after($text,"") let $xmp := concat("") return util:parse($xmp) };

let $photo := request:get-parameter("photo",) let $xmp := local:extract-xmp(concat("/db/Wiki/eXist/",$photo)) return $xmp

XMP XML

= Some basic Dublin Core elements =

Here we extract a few of the Dublin Core elements and create an HTML fragment containing the image and the meta-data.

declare namespace dc="http://purl.org/dc/elements/1.1/";

declare function local:extract-xmp ($jpeg as xs:string) as item { ..... };

declare option exist:serialize "method=xhtml media-type=text/html";

let $photo := request:get-parameter("photo",) let $xmp := local:extract-xmp(concat("/db/Wiki/eXist/",$photo)) return    Format : {string($xmp//dc:format)} Title: {string($xmp//dc:title)} Creator: {string($xmp//dc:creator)} 

Basic Dublin Core elements