XQuery creates HTML including images
XQuery is known to query and produce XML, but how can it be used to produce images, JPEG files in this particular example? This is another example where the DataDirect XML Converters come to rescue.
The JPEG images are stored in our database, and are retrieved by DataDirect XQuery as xs:hexbinary data. Subsequently the DataDirect XML Converters are used to convert the xs:hexbinary into a binary stream, which is saved as a JPEG file.
The following query shows how to generate the main HTML page which references the JPEG files. The idea here is to save the HTML document in the same directory as the JPEG files.
The table in our SQL Server database is fairly simple, having 3 columns with the name of the image, a small description and the actual picture.
<html>{
"My favourite pictures.",<p/>,
(: loop over all images in the database:)
for $image in collection("images")/images
(: the file name of the JPEG file :)
let $filename := concat($image/name, ".jpg")
(: create some virtual XML, which will be
processed by the XML Converters :)
let $jpeg := <jpeg>{$image/image/text()}</jpeg>
return
(<a href="./{$filename}">{
$image/description,
(: create the JPEG file :)
ddtek:serialize-to-url($jpeg,
concat("C:/test", $filename),
"method=binary")
}</a>,
<br/>)
}</html>In this example we've used JPEG files, but you can apply the outlined technique with any other binary format.Labels: XQuery

0 Comments:
Post a Comment
<< Home