473,396 Members | 2,030 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,396 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 26162
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.