Tony The Lion
Tony The Lion

Reputation: 63250

include image in XML file

I want to be able to send an image from HTML page to a XML file using C#.

The image should be sent along with some text, the problem is how do I store the image in the XML file efficiently, so it can be sent over the wire and how do I store the position of the image on the HTML page, so it can be restored later in the original position?

I was originally going to keep a hyperlink in my XML file to an image and load it that way on the HTML page, using ASP.NET, but I wondered if there's better ways?

EDIT:

So how do I keep the coordinates of the picture in the page in relation to all other objects. What ways can I save it to the XML file and how do I get the coordinates? Using ASP.NET, HTML and or JavaScript?

Upvotes: 0

Views: 1401

Answers (5)

Pete Kirkham
Pete Kirkham

Reputation: 49331

You could encode the image as a data URI, which most browsers seem to support now. It's still base 64, and so less compact than a separate binary file, but it is a standard way of inlining small images.

Upvotes: 0

Matt
Matt

Reputation: 3812

Follow the KISS principle.

Do what you were originally going to do, and keep the link in the file.

Upvotes: 0

philsquared
philsquared

Reputation: 22493

You can do it but its a really bad idea. If this is in an ASP.Net context then the hyperlink method sounds much more reasonable.

However, if you insist on encoding images in XML, then have a look at base64 encoding or ASCII 85.

Upvotes: 4

Benjamin Podszun
Benjamin Podszun

Reputation: 9837

I wouldn't recommend doing this (better add a link on the serverside that you can reference a < img />, like http://yourhost/someGuid maybe, and leave the serialization to your webserver and the browser), but base64 would be an easy option for your usecase.

Upvotes: 0

Oded
Oded

Reputation: 499202

There are binary xml specifications out there for sending of such data via xml, but these don't cater to your specific "position of the image" issue.

I would simply keep the image URL and use that.

Upvotes: 0

Related Questions