Jump to content

Images in XML


danielkraus

Recommended Posts

I am trying to find info on using images in an XML file to be part of the content in my XHTML document. I had read somewhere(can't remember where) that image files needed to be coded differently in XML. Is this true? I have seen some XML docs that have the .jpg files in the XML. Which is the most efficient way of using images in XML, or rather, what is the most accepted and widely used way? Thanx!!!!

Link to comment
Share on other sites

The most acceptable way is to do with images the same thing you do in HTML - instead of embedding the image in the file, link to it, i.e. do:

<img src="image.jpg" />

Or if the image must be embedded, use a data URI, like for example:

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9YGARc5KB0XV+IAAAAddEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q72QlbgAAAF1JREFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C7OwQg2JoQ9LE1exdlYvBBeZ7jqch9//q1uH4TLzw4d6+ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI97CER3N0vr4MkhoXe0rZigAAAABJRU5ErkJggg==" alt="Red dot" />

(if you give that directly to browsers, keep in mind that IE7- doesn't support it)

Link to comment
Share on other sites

How do I determine the base64 coding for an image? Just to make sure I understand, embedding an image means that it is contained within another tag or element, correct?For example:

<p><img src="x.jpg" /></p>

Would be an embedded image, correct?If that is true then, I do not neccesarily need to embed it. The images are to accompany the content. In my XHTML I have the image floated to left within the paragraph tag. I could use the DOM and XSLT to place it where I need, and not have t embedded, I think.Thanx

Link to comment
Share on other sites

When you specify an image's location, you're esentially linking to it. The same applies for videos, music and any other resource you might want to put on a web page.When the page contains the actual content of the image file, you're embedding the image.The second example I showed above is an embedded image. Embedded images take up images for every instance of theirs. I know of no way to actually link an embedded image. No standard way anyway (designing a custom XML dialect that would allow that is another story).I'd strongly advise you to link images instead of embedding them (i.e. do as in the first example I showed, or as in your example). It will keep your code cleaner, smaller, more readable and more efficient.If you really want to embed the image despite everything, PHP has a base64_encode() function with an accompanying decoder for the job. So the equivalent of

echo '<img src="dot.png" />';

would be:

echo '<img src="data:image/png;base64,' . base64_encode(file_get_contents('dot.png')) . '" />';

Link to comment
Share on other sites

Thank You for the clarification. I do not need to embed the images as each of the images will act as a link, and I am in no way ready to make an XML dialect :)I am staring to work on my XML XSLT and DOM. I plan to run a few practices before implementing it in my site's design. Thanx again!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...