Hey everyone. I wanted to use an HTTP reference within an image tag inside an XML file as opposed to having the image in a folder . Is that feasible?

Dani AI

Generated

Short answer: yes — an XML element or attribute can contain an HTTP/HTTPS URL and a consumer (browser script, XSLT, server-side parser) can fetch that image. That is essentially what meant: the XML just carries the path; the code that reads it must request the image. Important clarifications follow so the approach is reliable and safe.

XML does not itself render images. The reader of the XML must interpret the URL and perform the HTTP request. Remote images can be blocked, replaced, or rate-limited by the host (hotlinking concerns noted by ). Cross-origin requests for images are allowed by browsers for simple rendering, but operations like drawing to a canvas require the image server to send proper CORS headers, otherwise the canvas is tainted. Remote images may also require authentication or use signed/expiring URLs.

Practical patterns and tips:

  • Store the URL either as an attribute or element value; if using element content, escape special characters or wrap the URL in CDATA. Example patterns:

    <image src="https://example.com/picture.jpg" />
    <image><![CDATA[https://example.com/picture.jpg]]></image>
  • For embedding image data directly, use a data URI (base64) inside CDATA, but expect much larger XML and higher memory/transfer cost.

  • If hotlinking is not acceptable, use a server-side proxy/cache: fetch the remote image once, validate Content-Type/size, store it, and rewrite the XML URL to the local copy.

  • For relative URIs, ensure a known base (xml:base or the parser/HTTP base) so the URL resolves correctly.

  • Prefer HTTPS and verify the response status and Content-Type before trusting the resource.

Quick troubleshooting checklist: verify the URL responds with 200 and correct MIME type, check referer/CORS/restrictions, handle timeouts and fallbacks, and implement caching or local hosting when reliability or licensing is a concern.

Recommended Answers

All 4 Replies

Member Avatar for Member #334542

What you are going to do?

Reading <img tag> as a string from xml with the image folder path?

That's the good idea to read no of external images!

No, I want it to go something like this

<image>http://www.somewhereontheinternet.com/image.jpg</image>

Will that work or do image have to be in a folder of the same site where the XML file is?

Member Avatar for Member #334542

No need, The above code is right! But anyway you are going to read the tag value ("") and going to call the relevant file from you code, then don't worry where it resides. It will be anyside, your server or some other site. But the code should call the path....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.