BizTalk Utilities CV ,   Jobs ,   Code library  
 
 
Page 1 of 2

 

 Next Page

XML and Binary Data

The following article has been sponsored by:

Perfect XML

by Darshan Singh

This article assumes you're familiar with XML, ADO, & XMLDOM.

Download the source:Zip

Introduction

XML, or eXtensible Markup Language, is a method for putting structured data in a text file. Structured data refers to data that is tagged for its content, meaning or use. To better understand, let's look at a XML document that describes a bank account:

<?xml version="1.0" standalone="yes"?>
     <BankAccount>
          <Number>1234</Number>
          <Type>Checking</Type>
          <OpenDate>11/04/1974</OpenDate>
          <Balance>25382.20</Balance>
          <AccountHolder>
          <LastName>Singh</LastName>
          <FirstName>Darshan</FirstName>
     </AccountHolder>
</BankAccount>

In above document, each custom tag explicitly identifies the kind of information, for example <Balance> tag identifies the money I have in my bank account (don't trust above XML document!), <OpenDate> tag identifies the date on which account was opened, and so on. HTML is used to tell how to present the document, but XML is used to describe structure and content of the document.

XML solves varieties of problems. Keeping in mind that XML is not only for web development. It can be used for virtually any kind of application - which depends on your imagination. It's best suited to pass data across machines running different platform/operating system, because everybody understands plain text.

But what if, part of your document is not text; it is binary, for instance, an image? Does XML answer this question? The answer is yes, and in this article I'll show you how to pass binary data as part of XML document and we will learn this by passing a signature image file associated with each bank account, as an example.

The Answer

To send the binary data as part of XML document, it needs to be encoded using base64 encoding scheme.

Base64 encoding, specified in RFC 2045 - MIME (Multipurpose Internet Mail Extensions) uses a 64-character subset (A-Za-z0-9+/) to represent binary data and = for padding. Base64 processes data as 24-bit groups, mapping this data to four encoded characters. It is sometimes referred to as 3-to-4 encoding. Each 6 bits of the 24-bit group is used as an index into a mapping table (the base64 alphabet) to obtain a character for the encoded data. According to the MIME specification the encoded data has line lengths limited to 76 characters, but this line length restriction does not apply when transmitting binary data as part of XML document.

The Solutions

Binary data to base64 encoding and back can be done in many ways. We can write our own COM DLL that exposes methods to encode and decode the data and then call that DLL from our ASP code/JScript code. Microsoft ships a sample, which highlights sample base64 encoding and decoding. Have a look at Q191239 (http://support.microsoft.com/support/kb/articles/Q191/2/39.ASP). Also, SOAP toolkit for Visual Studio (http://msdn.microsoft.com/xml/general/toolkit_intro.asp) has a base64 encoder/decoder.

You can also use the Microsoft Parser DLL (MSXML.DLL) to do base64 encoding and decoding. We'll use msxml parser in this article.

Page 1 of 2

 

 Next Page
 

Recent Jobs

Integration Specialist Needed - Wor
Virtualization Server Infrastructur
A great opportunity to Digital Vide
here is a greate opportunity as a S
A great opportunity as a Network En

View all Jobs (Add yours)
View all CV (Add yours)




Chicago Web Site Design
wigs
fax server
Diesel sunglasses
air freshener
odor remover


    Email TopXML  

Front Page Daily Stuff TopXML Forum XML blogs XML Newsgroups BizTalk Biztalk Utilities Biztalk Utilities Tutorial B2B SAP XML Microsoft .NET Dotnet System XML Soapformatter SQLXML XMLserializer XQuery PHP PHP SimpleXML PHP XML Dom PHP XML RPC PHP XSLT Java Java Java XML Xalan Microsoft ASP ASP Schemas XML SQL Server XML XMLDom XSL XSL Tutorial XSLT Stylesheets General Javascript CSS XHTML WAP