473,324 Members | 2,581 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Store Image inside XML

Hi,

I need to store an image from a Graphics object(.NET) inside a xml
data island. Anyone might have came accross or have an idea how to do
this. Please share.

Thanks & Regards,
Raghu, CSS India
+91 98402 56561

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #1
10 26149
Raghavendra RAV wrote:
I need to store an image from a Graphics object(.NET) inside a xml
data island. Anyone might have came accross or have an idea how to do
this. Please share.


XML doesn't support storing binary data directly, use Base64 encoding
(e.g. use XmlTextWriter.WriteBase64() method).

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #2
Hi Oleg,

Thanks for the reply.

It is correct that XML doesnt support binary data. If i manage to
store image inside xml, pls suggest me how can i get the image back on
my web page (possibly using xslt).

Also if possible pls suggest me how to save image in Graphics object
of .NET to base64 data.
Thanks and Regards,
Raghu, CSS India
+91 94440 37040

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #3
> Also if possible pls suggest me how to save image in Graphics object
of .NET to base64 data.


Have a look at
Convert.ToBase64String
Regards,

Victor
Nov 12 '05 #4
Raghavendra RAV wrote:
It is correct that XML doesnt support binary data. If i manage to
store image inside xml, pls suggest me how can i get the image back on
my web page (possibly using xslt).
XML is text based format. So to store binary data in it you must encode
it. Usually Base64 encoding is used. When you put image to XML - encode
it (e.g. using XmlTextWriter.WriteBase64() method).
When you read XML, you need to decode image (e.g. using
XmlTextReader.ReadBase64() method).
Also if possible pls suggest me how to save image in Graphics object
of .NET to base64 data.


Basically XML API can handle it itself, but if you want take over - use
Convert.ToBase64String()/Convert.FromBase64String() methods.

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #5
> It is correct that XML doesnt support binary data. If i manage to
store image inside xml, pls suggest me how can i get the image back on
my web page (possibly using xslt).


.... I think that there is no "direct" way to embedd the image into a web
page after you've decoded it from Base64.

What happens when a browser reads an html file is that it makes an
additional request for every image it finds defined inside the html code -
they're two different files on the web server, and two different http calls
from the browser.

So, I think it's gonna be *difficult* to use xslt or any other medioum and
"embed" the image inside the html.
( of course I'm not an HTTP expert, but I've been working on web sites for
years and have never come across html that contains the full image data
instead of a link to the actual source of the image :? ... )

Of course, nothing prevents you from actually saving the image on the file
system, and just modifying your html link src to point to the right file on
the web server - although that would be A LOT of reading/writing to the disk
and I'd try to avoid it at all costs ...

Angel
O:]
Nov 12 '05 #6
Actually you can display base-64 images inline, using the data url format -
see the spec. at http://www.ietf.org/rfc/rfc2397.txt .

You'd have to use xslt to convert the xml to something in the format
<IMG SRC="data:image/gif,base64;[...]">where the [...] contains your base-64
string.The only issue with this is the size limit on HTML tags, which is
usually 1,024 bytes. This inline data url method is only meant for very
small amounts of data.Hugo Rodger-Brownhttp://hugo.rodger-brown.com
Nov 12 '05 #7
Hi Brown,

Exactly this kind of this is what i was expecting. Thank you so much
for ur reply. I am yet to test this and if i get any issues i may need
ur help.

Thanks,
Raghu, CSS India
+91 94440 37040

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #8
Well, I stand corrected ! Thanks for the post Hugo, that was something I'd
never seen before, and it's certainly useful in many cases. Do you happen to
know when support for this became commonplace ? I'm afraid that I left html
guis a few years ago and .. god, am i obsolete ?!??!?

Cheers,
Angel
O:]

"Hugo Rodger-Brown" <hu**@coldhams.com> wrote in message
news:eG**************@TK2MSFTNGP11.phx.gbl...
Actually you can display base-64 images inline, using the data url format - see the spec. at http://www.ietf.org/rfc/rfc2397.txt .

You'd have to use xslt to convert the xml to something in the format
<IMG SRC="data:image/gif,base64;[...]">where the [...] contains your base-64 string.The only issue with this is the size limit on HTML tags, which is
usually 1,024 bytes. This inline data url method is only meant for very
small amounts of data.Hugo Rodger-Brownhttp://hugo.rodger-brown.com

Nov 12 '05 #9
Hugo Rodger-Brown wrote:
Actually you can display base-64 images inline, using the data url format -
see the spec. at http://www.ietf.org/rfc/rfc2397.txt .

You'd have to use xslt to convert the xml to something in the format
<IMG SRC="data:image/gif,base64;[...]">where the [...] contains your base-64
string.The only issue with this is the size limit on HTML tags, which is
usually 1,024 bytes. This inline data url method is only meant for very
small amounts of data.Hugo Rodger-Brownhttp://hugo.rodger-brown.com


Of course it should be mentioned IE doesn't support this cool stuff.
Another option to give a shot is MHT format, but I never tried that.

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #10
One more option would be to go for VML if your graphic could be represented
as a vector type image and you are using IE, or SVG + a plugin if you need
cross browser support.

Also, is there no way that you could just use a URL inside your XML data,
and keep the graphic as an external binary resource?

Nigel

Nov 12 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Karen Grube | last post by:
Hi! Each week, we receive a two-page PDF file from UPS along with a separate flat file (a CSV) The PDF file contains the overview of our weekly invoice and the CSV contains the details of each...
6
by: Rudy | last post by:
Hello all! I am amazed how many posts I have read to store an image in SQL, and just as many against it. So I learned how to store an image in a SQL db and retrieve the image. A little tricky,...
5
by: moondaddy | last post by:
I'm caching a dataset in an asp.net session variable to hold a user's data. one data item I need to store is an image the user uploaded. My problem is that I don't know how to get the image into...
2
by: wschanks | last post by:
I have an .adp (Access 2003) file and I need to store files in a field on the database. I have figured out that I need the data type to be 'Image', so I have my table with the this datatype. ...
2
by: sachaburnett | last post by:
Hi everyone! I'm new to Javascript and am finding so much useful information on this group, so thanks to you all! I have a question about preloading images for onmouseover/out effects and...
0
by: wizardworkz | last post by:
Hello All! Having a bit of a problem combining php with javascript here. What I have is a store with images (There will be a smaller image of each item, and a larger image of each item, but I want...
4
by: =?Utf-8?B?YWxiZXJ0b3Nvcmlh?= | last post by:
Hi everydoby! I have an issue, I have an static image, and I need to write text inside it in runtime, but I don't know how! I can't use absolute position in atributtes style. Thanks.
1
by: sourcie | last post by:
I am changing an existing quiz found on "JavaScriptKit.com Multiple Choice Quiz" I have an image. Instead of using the radio buttons with the normal true/false question, I want to place two...
8
meenakshia
by: meenakshia | last post by:
hi i m not sure but wanted to use a variable to store an image and then show it inside the table something like var img1; img1="c:\myself.jpg"; and inside the table it shows like <table>...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.