开发者

include image in XML file

开发者 https://www.devze.com 2022-12-14 14:27 出处:网络
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

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开发者_Go百科, HTML and or JavaScript?


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.


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.


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.


Follow the KISS principle.

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消