Click here to Skip to main content
Click here to Skip to main content

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

, 13 Jun 2001
Rate this:
Please Sign up or sign in to vote.
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
<!-- Article image -->

Sample Image - screen_shot_Genx.jpg

<!-- Add the rest of your HTML here -->

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,"");

<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!) Smile | :)

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

Share

About the Author

Wahid Choudhury

United States United States
No Biography provided

Comments and Discussions

 
GeneralXML file with binary data Pinmembersranu26-Oct-10 8:38 
GeneralPassing Binar/Image data to a web service Pinmembersheel prabhakar14-Sep-10 2:40 
QuestionHow to convert .ai file(Adobe Illustrator File) to .bmp(BitMap) file in c# PinmemberSanthosh_B_K16-Apr-07 2:08 
Questionhow do I pass an image from nodes in the xml to a component on a form PinmemberTry748-Jan-07 2:15 
Generalssl code Pinmembersaroj yadav16-Oct-06 2:20 
GeneralThank You Pinmemberdboucher21-Jul-05 18:01 
GeneralBinary to XML to Binary to XML fails Pinmembernordhaus18-May-05 12:34 
GeneralXmlTextReader and binary data PinsussAnonymous10-Dec-02 5:45 
Generaldbconsts.obj PinsussReza_Y20-Sep-02 23:07 
GeneralSending the image size PinmemberVinla20-Sep-02 1:24 
GeneralBitmap to a bytearray Pinmemberjeetu26-Aug-02 5:44 
GeneralRe: Bitmap to a bytearray PinmemberKamen Nikolov26-Sep-03 7:45 
GeneralRe: Bitmap to a bytearray PinmemberKamen Nikolov26-Sep-03 7:55 
GeneralXml bunary vb6 problem in c# Pinmemberbcapuano30-Jul-02 13:25 
GeneralRe: Xml bunary vb6 problem in c# PinsussAnonymous4-Oct-02 12:44 
GeneralXml Quik Buider Pinmembershak30-Jun-02 20:48 
GeneralRe: Xml Quik Buider PinmemberChristian Graus30-Jun-02 21:09 
QuestionCan you encode the binary information to a string PinmemberAnonymous13-Jul-01 11:56 
AnswerRe: Can you encode the binary information to a string PinmemberTodd Smith13-Jul-01 12:36 
GeneralRe: Can you encode the binary information to a string PinmemberAnonymous16-Jul-01 9:51 
GeneralRe: Can you encode the binary information to a string PinmemberNathan Blomquist12-Jun-02 7:07 
GeneralAnything like this in C++ PinmemberDarren Schroeder16-Jun-01 11:39 
GeneralRe: Anything like this in C++ Pinmemberwahid18-Jun-01 6:02 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141223.1 | Last Updated 14 Jun 2001
Article Copyright 2001 by Wahid Choudhury
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid