Click here to Skip to main content
15,884,838 members
Articles / Programming Languages / C#
Article

Passing binary data in xml: a C# example which puts and gets icon and bitmaps to and from a xml file.

Rate me:
Please Sign up or sign in to vote.
3.27/5 (11 votes)
13 Jun 20011 min read 199.8K   4.2K   49   23
Binary data needs to be base64 encoded to go into an xml file. .Net framework has made this a painless method wiht its System.Xml namespce classes. I use the XmlTextWriter to put in a bitmap and icon image into a xml file. I then use XmlTextReader to parse the xml file and dynamically set the icon a

Sample Image - screen_shot_Genx.jpg

Introduction

Looking at the .resx file that VS.NET uses to store resources such as images, I thought wouldn't it be cool to have a XML file where you can store images and other info for you app and at startup your app gets the look and feel from the XML file dynamically. You can then change the look and feel by changing the XML file, maybe over the internet! A little investigation showed that .NET namespace System.XML has 2 great classes XMLTextWriter and XMLTextReader which does all the hard work for you with their Read/WriteBase64 methods.

m_XMLWriter.WriteStartElement("",NodeName,"");</P>
<P><code>m_XMLWriter.WriteBase64(ImageBinaryBuffer,0,ImageBinaryBuffer.Length);

m_XMLWriter.WriteEndElement();

So here is my quick and dirty app, which uses 2 classes CLookXMLReader and CLookXMLWriter to do the putting in the binary and getting the binary out to bitmap or an icon. You basically use the Writer to put the images into the XML, then the reader can be used at a separate app to get the images out from the XML. Made the code a bit messy when reading the binary out from the XML, there must be a better way to it, please let me know! I hope you dont judge coding skills by just looking at this app only (I am usually much better!) :)

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralXML file with binary data Pin
sranu26-Oct-10 7:38
sranu26-Oct-10 7:38 
GeneralPassing Binar/Image data to a web service Pin
sheel prabhakar14-Sep-10 1:40
sheel prabhakar14-Sep-10 1:40 
QuestionHow to convert .ai file(Adobe Illustrator File) to .bmp(BitMap) file in c# Pin
Santhosh_B_K16-Apr-07 1:08
Santhosh_B_K16-Apr-07 1:08 
Questionhow do I pass an image from nodes in the xml to a component on a form Pin
Try748-Jan-07 1:15
Try748-Jan-07 1:15 
Generalssl code Pin
saroj yadav16-Oct-06 1:20
saroj yadav16-Oct-06 1:20 
GeneralThank You Pin
dboucher21-Jul-05 17:01
dboucher21-Jul-05 17:01 
GeneralBinary to XML to Binary to XML fails Pin
nordhaus18-May-05 11:34
nordhaus18-May-05 11:34 
GeneralXmlTextReader and binary data Pin
Anonymous10-Dec-02 4:45
Anonymous10-Dec-02 4:45 
Generaldbconsts.obj Pin
Yaghoobi_R20-Sep-02 22:07
Yaghoobi_R20-Sep-02 22:07 
GeneralSending the image size Pin
Vinla20-Sep-02 0:24
Vinla20-Sep-02 0:24 
GeneralBitmap to a bytearray Pin
jeetu26-Aug-02 4:44
jeetu26-Aug-02 4:44 
GeneralRe: Bitmap to a bytearray Pin
Member 60063226-Sep-03 6:45
Member 60063226-Sep-03 6:45 
GeneralRe: Bitmap to a bytearray Pin
Member 60063226-Sep-03 6:55
Member 60063226-Sep-03 6:55 
GeneralXml bunary vb6 problem in c# Pin
Bruno Capuano30-Jul-02 12:25
Bruno Capuano30-Jul-02 12:25 
GeneralRe: Xml bunary vb6 problem in c# Pin
Anonymous4-Oct-02 11:44
Anonymous4-Oct-02 11:44 
GeneralXml Quik Buider Pin
shak30-Jun-02 19:48
shak30-Jun-02 19:48 
GeneralRe: Xml Quik Buider Pin
Christian Graus30-Jun-02 20:09
protectorChristian Graus30-Jun-02 20:09 
QuestionCan you encode the binary information to a string Pin
13-Jul-01 10:56
suss13-Jul-01 10:56 
AnswerRe: Can you encode the binary information to a string Pin
Todd Smith13-Jul-01 11:36
Todd Smith13-Jul-01 11:36 
GeneralRe: Can you encode the binary information to a string Pin
16-Jul-01 8:51
suss16-Jul-01 8:51 
GeneralRe: Can you encode the binary information to a string Pin
Nathan Blomquist12-Jun-02 6:07
Nathan Blomquist12-Jun-02 6:07 
GeneralAnything like this in C++ Pin
Darren Schroeder16-Jun-01 10:39
Darren Schroeder16-Jun-01 10:39 
GeneralRe: Anything like this in C++ Pin
18-Jun-01 5:02
suss18-Jun-01 5:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.