iNSErting an image into xml document

a1jit

Well-known member
Joined
Aug 19, 2005
Messages
89
Hi Guys,

I have been browsing through the net and tried finding some examples to
get an image displayed in an xml tag, some say use xlink and some say use xslt.But did not manage to get it done..

I have the following xml structure

Code:
writer.WriteStartElement ("image");
writer.WriteAttributeString ("display","");
writer.WriteEndElement();

How can i insert an image in the "display" attribute tag?

Thank you very much
 
Not entirely sure what you are trying to do here. Are you trying to store a link to an image or store the actual image itself in the XML file?
 
hi, i plan to display the actual image in the xml

Meaning when user request for a particular xml page, it displays content, plus the image in a specific element.

So how can i embed a picture in an xml element? Would really appreciate if someone could show an example here..thank you
 
Last edited by a moderator:
You are trying to store actual image data as opposed to an image name? This makes a world of difference. IMHO, It certainly wouldnt make much sense to store image data as an attribute. You should probably put the image data as the content of the Image element.

XML isnt exactly ideal for binary data storage. Binary data and the XML format dont play together nicely, so the data has to be formatted, which tends to cause bloat. The way that Visual Studio stores binary data in XML files is to store hexidecimal values. If the file is saved as Unicode this could as much as quadrouple the size of the binary data, and if the file is ASCII, it would double the size of the data. Typical binary data would probably look something like the following:
Code:
<[COLOR=DarkRed]SomeXmlTags[/COLOR]>
    <[COLOR=DarkRed]Image [/COLOR][COLOR=DarkOrange]Name[/COLOR]=[COLOR=Blue]"Cowabunga.bmp"[/COLOR]>
[COLOR=Blue]        D1C5A4F8B7E1C3B4E6A0F9B0C0E3A4B5F3C2A3
        E1C5H8I9D6D3E1N400M1E5S7S7A4G1E2!5B8F0
        C1A9E5B8F5C8A7E7C0F0A1E2B1F0C5A3E2B4A5
        D8W6F9B5C7D1A5W2B5C4F0D1A4W2F6B5C3B2A4
        D2A4W8A6W5D7B4C5D4A1W0B1F2C1D0A1A1A4B1
        C0B6I5N4A8R5Y600I8S400D2A400B4O1M4B3A6
        F4C6B7C8F9B4F1A3C5D2A6W4C7B5F2A3D6W9B5
        C1D5A4W0B1C2F3D5A2W2A1A0B2A1C4F5A2[/COLOR]
    </[COLOR=DarkRed]Image[/COLOR]>
</[COLOR=DarkRed]SomeXmlTags[/COLOR]>
When the XML is obtained, the binary data can be extracted to a byte array, which can be used to create a memory stream which can be passed to the System.Drawing.Bitmap constructor.

Im not positive that this is what you are after. It almost sounds like you want someone to download an XML file, open it with IE or Visual Studio or whatever, and have an image show up, but that cant really be done.
 
Hi, thanks for the reply,

Actually i have an image stored in some folder. for example, lets name it x.gif

I want to call the image when user invoke the xml page.

Meaning lets say users invokes test.aspx, this page will basically display to user
some data in xml form , and in one of the xml element, i want to display this image,

Meaning instead of having only text based elements, i want to be able to embed a picture in the element..Is this possible?

Meaning lets say i have the following xml structure

Code:
- <analyses>
  <analysis id="1" name="Fabrication" fullName="Fabrication Analysis" /> 
  <analysis id="21" name="Assembly" fullName="Assembly Analysis" /> 
  </analyses>

How do i create another attribute, "picture" for example, and displayed the picture there, meaning this is the result i wish to achieve

Code:
- <analyses>
  <analysis id="1" name="Fabrication" fullName="Fabrication Analysis" image="somerealimage" /> 
  <analysis id="21" name="Assembly" fullName="Assembly Analysis" image="somerealimage" /> 
  </analyses>

the image attribute will basically have a image there. meaning user will not
see any text for the "image" attribute, they will see a real image there
 
Last edited by a moderator:
The XML file could contain the path to the real image file as a named attribute - however opening the xml file would just display the XML as is and not the image; this is by design as XML is a storage mechanism not a display medium.

If you want to be able to store data in XML and view it in a different format via a browser then you may want to look at XSLT as this will allow you to do this (as well as a lot of other things).
 
Back
Top