Click here to Skip to main content
Licence 
First Posted 13 Jun 2001
Views 138,751
Downloads 2,942
Bookmarked 44 times

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

By Wahid Choudhury | 13 Jun 2001
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
4 votes, 40.0%
1
1 vote, 10.0%
2

3
3 votes, 30.0%
4
2 votes, 20.0%
5
3.11/5 - 14 votes
μ 3.11, σa 3.06 [?]

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

<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

About the Author

Wahid Choudhury



United States United States

Member


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralXML file with binary data Pinmembersranu8:38 26 Oct '10  
GeneralPassing Binar/Image data to a web service Pinmembersheel prabhakar2:40 14 Sep '10  
QuestionHow to convert .ai file(Adobe Illustrator File) to .bmp(BitMap) file in c# PinmemberSanthosh_B_K2:08 16 Apr '07  
Questionhow do I pass an image from nodes in the xml to a component on a form PinmemberTry742:15 8 Jan '07  
Generalssl code Pinmembersaroj yadav2:20 16 Oct '06  
please send ssl code
GeneralThank You Pinmemberdboucher18:01 21 Jul '05  
GeneralBinary to XML to Binary to XML fails Pinmembernordhaus12:34 18 May '05  
GeneralXmlTextReader and binary data PinsussAnonymous5:45 10 Dec '02  
Generaldbconsts.obj PinsussReza_Y23:07 20 Sep '02  
GeneralSending the image size PinmemberVinla1:24 20 Sep '02  
GeneralBitmap to a bytearray Pinmemberjeetu5:44 26 Aug '02  
GeneralRe: Bitmap to a bytearray PinmemberKamen Nikolov7:45 26 Sep '03  
GeneralRe: Bitmap to a bytearray PinmemberKamen Nikolov7:55 26 Sep '03  
GeneralXml bunary vb6 problem in c# Pinmemberbcapuano13:25 30 Jul '02  
GeneralRe: Xml bunary vb6 problem in c# PinsussAnonymous12:44 4 Oct '02  
GeneralXml Quik Buider Pinmembershak20:48 30 Jun '02  
GeneralRe: Xml Quik Buider PinmemberChristian Graus21:09 30 Jun '02  
QuestionCan you encode the binary information to a string PinmemberAnonymous11:56 13 Jul '01  
AnswerRe: Can you encode the binary information to a string PinmemberTodd Smith12:36 13 Jul '01  
GeneralRe: Can you encode the binary information to a string PinmemberAnonymous9:51 16 Jul '01  
GeneralRe: Can you encode the binary information to a string PinmemberNathan Blomquist7:07 12 Jun '02  
GeneralAnything like this in C++ PinmemberDarren Schroeder11:39 16 Jun '01  
GeneralRe: Anything like this in C++ Pinmemberwahid6:02 18 Jun '01  

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.

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