(This example can be provided in all programming languages supported by Chilkat: C#, ASP, VB.NET, C++, Delphi, Perl, Python, Ruby, Java, etc.)
This Visual Basic 6.0 example converts a base64-gzip .xfdl file to a decompressed XML string.
' This code converts Gzip'd XFDL to the uncompressed XML document
' contained in a string. The .xfd document to be converted looks like this:
'
' application/vnd.xfdl;content-encoding="base64-gzip"
' H4sIAAAAAAAAC x9adOa2Nbod38FN6fq7T5lEgYFoU86pxBQUQRkcLp1K4VMokwyOfz6u9FnftQk
' 3Zon6deuTiLszZ7WvPbaa3/67ybwocJOUi8K/3yHfkTeQXZoRpYXun++41XpA0ni1Af03X8/Vz6N
' ...
' CkString is a freeware String component. It may be downloaded from:
' <a href=\"http://www.chilkatsoft.com/download/ckString.zip\">http://www.chilkatsoft.com/download/ckString.zip</a>
‘ Reference Doc: <a href=\"http://www.chilkatsoft.com/refdoc/xCkStringRef.html\">http://www.chilkatsoft.com/refdoc/xCkStringRef.html</a>
Dim ckStr As New CkString
Dim success As Long
success = ckStr.LoadFile("test.xfdl", "iso-8859-1")
If (success = 0) Then
MsgBox "Failed to load file!"
Exit Sub
End If
‘ Get rid of the 1st line:
ckStr.ChopBefore CStr(Chr(10))
‘ The Gzip component is included in the Chilkat Zip ActiveX.
‘ It requires a "Chilkat Zip" license to use beyond 30-days.
‘ Download link: <a href=\"http://www.chilkatsoft.com/preRelease/ChilkatGzip.zip\">http://www.chilkatsoft.com/preRelease/ChilkatGzip.zip</a>
‘ GZip reference: <a href=\"http://www.chilkatsoft.com/refdoc/xGzipRef.html\">http://www.chilkatsoft.com/refdoc/xGzipRef.html</a>
Dim gzip As New gzip
success = gzip.UnlockComponent("Anything for 30-day trial")
If (success = 0) Then
‘ Failed to unlock component
MsgBox gzip.LastErrorHtml
Exit Sub
End If
‘ Decode from base64 to binary (a Variant containing the Gzip bytes)
Dim binaryData As Variant
binaryData = gzip.Decode(ckStr.Str, "base64")
‘ Ungzip:
Dim xmlBytes As Variant
xmlBytes = gzip.UncompressMemory(binaryData)
‘ We now have the XML bytes (a Variant containing a byte array)
‘ You might be tempted to assign this to a string — but don’t –
‘ you don’t yet know the character encoding of the XML. If it’s non-ANSI,
‘ you’d ruin the document.
‘ Load the XML document into a CkString object:
Dim xmlStringObj As New CkString
‘ The LoadXmlDoc method parses just enough of the XML bytes to get the charset.
‘ It looks for the XML declaration, such as this:
‘ <?xml version="1.0" encoding="utf-8"?>
‘ If not found, it assumes ANSI.
‘ This allows the XML bytes to be interpreted correctly according to the
‘ character encoding used.
xmlStringObj.LoadXmlDoc xmlBytes
‘ Now get the XML document as a String:
Dim xmlString As String
xmlString = xmlStringObj.Str
Text1.Text = xmlString