This nice bit of XQuery comes from my colleague Kelly
Stirman:
It’s really cool and a huge time and headache saver for people who handle photos.
And it’s even cooler that, using XQuery and the standard MarkLogic extensions, you can load the image into MarkLogic and Query the XMP directly:
Step 1: Load an image with XMP.
How about this picture a boat
I took in
Using the MarkLogic update extenstions to XQuery, you can just go ahead and pull it from my blog and upload it into the MarkLogic Server you have set up in the Tutorial:
xdmp:document-load(
"http://xquery.typepad.com/photos/uncategorized/maineboat.jpg",
<options
xmlns="xdmp:document-load">
<uri>/xmp/maine-boat.jpg</uri>
</options>
)
declare namespace
dc="http://purl.org/dc/elements/1.1/"
declare namespace
tiff="http://ns.adobe.com/tiff/1.0/"
declare namespace
rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
declare namespace x="adobe:ns:meta/"
(: get the image :)
let $doc := doc("/xmp/maine-boat.jpg")
(: make a string out of the image using the MarkLogic Server
extension xdmp:quote :)
let $node := xdmp:quote($doc/node())
(: isolate the <x:xmpmeta> node in the string using
substring-before and substring-after :)
let $xmp := substring-after($node,"<x:xmpmeta")
let $xmp :=
substring-before($xmp,"</x:xmpmeta>")
(: put back the stuff we took out with out after and before
:)
return
{$xmp/x:xmpmeta/rdf:RDF/rdf:Description/dc:title}
{$xmp/x:xmpmeta/rdf:RDF/rdf:Description/dc:creator}
{$xmp/x:xmpmeta/rdf:RDF/rdf:Description/dc:subject}
</image>
Very nice! We are
storing the original binary (you can display it as an image any time) and are
easily able to unlock the content contained within it.
Welcome to the new world of self-describing content!
Comments