<?xml version="1.0" encoding="iso-8859-1"?> <?xml-stylesheet href="../../make-menu.xsl" type="text/xsl"?><html> <head> <this-is section="extensions" page="output-extras" subpage="hexBinary-method"/> <!-- Generated at 2011-12-09T20:47:22.916Z--><title>Saxonica: XSLT and XQuery Processing: The saxon:hexBinary serialization method</title> <meta name="coverage" content="Worldwide"/> <meta name="copyright" content="Copyright Saxonica Ltd"/> <meta name="title" content="Saxonica: XSLT and XQuery Processing: The saxon:hexBinary serialization method"/> <meta name="robots" content="noindex,nofollow"/> <link rel="stylesheet" href="../../saxondocs.css" type="text/css"/> </head> <body class="main"> <h1>The saxon:hexBinary serialization method</h1> <p><i>Requires Saxon-PE</i></p> <p>An additional serialization method <code>saxon:hexBinary</code> is available. This is intended to be useful when creating binary output files, for example images. All serialization properties other than <code>method</code> are ignored.</p> <p>As with the <code>text</code> output method, all nodes in the result tree other than text nodes are ignored. Each text node must hold a string that is in the lexical space of the <code>xs:hexBinary</code> data type. The sequence of octets corresponding to this base64 value is written to the binary output file.</p> <p>When invoking this method via an API, use the property value "{http://saxon.sf.net/}hexBinary".</p> <p>When using this serialization method, the <code>omit-xml-declaration</code> parameter is automatically set to "yes".</p> <div class="codeblock" style="border: solid thin; background-color: #B1CCC7; padding: 2px"> <pre> <code><xsl:template name="main"> <html> <head> <title>An image</title> </head> <body> <h1>An image</h1> <p><img src="image004.gif"/></p> </body> </html> <xsl:result-document method="saxon:hexBinary" href="image004.gif" media-type="image/gif"> <xsl:text>89504E470D0A1A0A0000000D49484452</xsl:text> <xsl:text>0000000A0000000A08060000008D32CF</xsl:text> <xsl:text>BD0000000467414D410000B18F0BFC61</xsl:text> <xsl:text>05000000097048597300000B1300000B</xsl:text> <xsl:text>1301009A9C180000000774494D4507D6</xsl:text> <xsl:text>06011739281D1757E20000001D744558</xsl:text> <xsl:text>74436F6D6D656E740043726561746564</xsl:text> <xsl:text>2077697468205468652047494D50EF64</xsl:text> <xsl:text>256E0000005D4944415418D3BDCCBD0D</xsl:text> <xsl:text>825000C4F11F74B4ECE0164CE0320EE0</xsl:text> <xsl:text>2ECEC1083626843D2C4D5EC5D958BC10</xsl:text> <xsl:text>5E67B8EA721F7FFEAD6E1F84CBCF0E1D</xsl:text> <xsl:text>EBE12B5CC31C5EE1D6C4877728E1139E</xsl:text> <xsl:text>75D757A309A5CAB630B688F7B0844773</xsl:text> <xsl:text>74BEBE0C921A177B4AD98A0000000049</xsl:text> <xsl:text>454E44AE426082</xsl:text> </xsl:result-document> </xsl:template> </code> </pre> </div> <p><i>The image here displays as a small red dot. Note that whitespace cannot appear in the middle of an <code>xs:hexBinary</code> value, but the string can be split into multiple text nodes so long as each contains an even number of characters.</i></p> <p>It is of course possible to construct the hexBinary value programmatically. The extension function <a class="bodylink" href="../../extensions/functions/octetstohexbinary.xml">saxon:octets-to-hexBinary</a> may be useful to achieve this.</p> <p>When writing output that is not entirely binary, but contains mixed binary and text, it may be more convenient to use the text output method with the <a class="bodylink" href="../../extensions/output-extras/recognize-binary.xml">saxon:recognize-binary</a> serialization property.</p> <p>See also the <a class="bodylink" href="../../extensions/output-extras/base64Binary-method.xml">saxon:base64Binary</a> serialization method.</p> <table width="100%"> <tr> <td> <p align="right"><a class="nav" href="ptree-method.xml">Next</a></p> </td> </tr> </table> </body> </html>