|
How To: Retrieving binary data using XML (9323 Requests)
Answer provided by Srinivasa Burugapalli.
If you are not updating images or other binary data, the URL encode option is a better way to retrieve the images/binary data. Encoding and decoding large images is slow.
XML View/XPath and for XML auto mode generate a URL encoded result for binary/blob columns. This example XSL stylesheet retrieves images using the URL encoded result.
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output media-type="text/html" method="html"/>
<xsl:template match = "*">
<xsl:apply-templates />
</xsl:template>
<xsl:template match = "employees">
<TR>
<TD><xsl:value-of select = "@firstname" /></TD>
<TD><B><xsl:value-of select = "@lastname" /></B></TD>
<TD><img><xsl:attribute name="src"><xsl:value-of select="@photo"/></xsl:attribute></img></TD>
</TR>
</xsl:template>
<xsl:template match = "/">
<HTML>
<HEAD>
<STYLE>th { background-color: #CCCCCC }</STYLE>
</HEAD>
<BODY>
<TABLE border="1" style="width:300;">
<TR><TH colspan="3">Employees</TH></TR>
<TR><TH >First name</TH><TH>Last name</TH><TH>Photo</TH></TR>
<xsl:apply-templates select = "root" />
</TABLE>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>
Here is the XML template used with this example:
<root xmlns:sql="urn:schemas-microsoft-com:xml-sql">
<sql:query>
Select employeeid, firstname, lastname, photo
from employees
for xml auto
</sql:query>
</root>
In order to make this work you must map the template and you must create a dbobject mapping. To do this just create a new mapping of type dbobject and name it dbobject. You can also designate the stylesheet directly by using the sql:xsl attribute in the template. Below are the working examples of this.
Without Applying the StyleSheet
After Applying the StyleSheet
Feedback
# No dbobject in xml
12/2/2002 5:31 PM
hesterloli
I am not getting:
dbobject/employees[@EmployeeID='1']/@Photo
when I call the xml by itself in IE 6. There is a dbobject in my virtual directory set up. It is part of how you are to install it. What more am I supposed to do?
# No dbobject in xml
7/10/2003 7:03 PM
Roman
I am having the same difficulty. Templates work fine; but when I try to access dbobject, I get a 'page can not be found error'
# re: How To: Retrieving binary data using XML
7/12/2005 12:15 PM
shrek
links are not working.... too bad, this chapter could have helped me... :(
|