Click here to Skip to main content
6,594,932 members and growing! (13,902 online)
Email Password   helpLost your password?
Languages » C# » General     Beginner

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

By Wahid Choudhury

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
C#, Windows, .NET 1.0, Dev
Posted:13 Jun 2001
Views:117,934
Bookmarked:37 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
14 votes for this article.
Popularity: 3.56 Rating: 3.11 out of 5
4 votes, 40.0%
1
1 vote, 10.0%
2

3
3 votes, 30.0%
4
2 votes, 20.0%
5

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


Member

Location: United States United States

Other popular C# articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 21 of 21 (Total in Forum: 21) (Refresh)FirstPrevNext
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  
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  
GeneralCan you encode the binary information to a string PinmemberAnonymous11:56 13 Jul '01  
GeneralRe: 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    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 13 Jun 2001
Editor: Chris Maunder
Copyright 2001 by Wahid Choudhury
Everything else Copyright © CodeProject, 1999-2009
Web15 | Advertise on the Code Project