411 REFERENCE · Wikibooks
XQuery/XMP data
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
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,"<x:xmpmeta")
let $xmp := substring-before($xmp,"</x:xmpmeta>")
let $xmp := concat("<x:xmpmeta",$xmp,"</x:xmpmeta>")
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
<div>
<img src="../{$photo}"/>
<ul>
<li> Format : {string($xmp//dc:format)}</li>
<li>Title: {string($xmp//dc:title)}</li>
<li>Creator: {string($xmp//dc:creator)}</li>
</ul>
</div>
Basic Dublin Core elements