跳轉到內容

XQuery/XMP 資料

來自華夏公益教科書

Adobe 推出了一個用於影像元資料的 XML 格式,稱為 XMP。 您想顯示一張照片和一些元資料。

Matt Turner 有一個使用 MarkLogic 從 JPEG 影像中提取 XMP 資料的示例 [1]

eXist/ XQuery 實現

[編輯 | 編輯原始碼]

以下是使用 eXist XQuery 擴充套件的程式碼。 Matt 的 " 照片 已儲存在 XML 資料庫中作為二進位制檔案。

顯示完整的 XMP XML

[編輯 | 編輯原始碼]

二進位制影像從資料庫中作為 BASE64 編碼字串檢索,轉換為 UTF-8 字串,提取元資料文字並使用 util:parse() 轉換回 XML

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

一些基本的 Dublin Core 元素

[編輯 | 編輯原始碼]

這裡我們提取一些 Dublin Core 元素並建立一個包含影像和元資料的 HTML 片段。

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>

基本的 Dublin Core 元素

華夏公益教科書