Skip to Content

Gareth53.co.uk - the online home of Gareth Senior

Cross Domain XML Include

2:24p.m., Tue 1 May 2007

I've just built an online radio player - a web page with an embedded windows media player object. The client also wanted the player to show the current DJ and the current track with both chunks of information available in XML format.

Simple enough I thought - load the XML using the ActiveX plug-in (or using document.implementation.createDocument) a bit of DOM script to parse the XML object I create and there you go - your standard AJAX stuff. Except.... the 2 XML files are on different domains.

The default security settings allow sloppy old IE mean to load a file from a different domain via a XMLhttpRequest object but other browsers (most notably Firefox) won't by default, not without the user adding the domain to their "trusted domains" list or manually changing the relevant security setting.

I figured I could load the remote file using an ASP script and re-write the XML to present to the browser. I read hundreds of articles and forum threads on line that told me it couldn't be done. But I managed to get it working. Here's the vbscript:

Response.ContentType = "text/xml" set xmldoc = Server.CreateObject("Microsoft.XMLDOM") xmldoc.async=false xmldoc.setProperty "ServerHTTPRequest", true xmldoc.Load("http://www.xxxxxx.xxx/feed.xml")

(IE was happy with loading XML from a file with the .asp file extension, but Firefox needed the mimetype explicitly declared.)

I then looped through the XML file and pretty much re-wrote the attributes and node.values that were found. It felt wrong, like an unnecessary step, it's definitely not a technique I would plan to use, but sometimes needs must.

Latest Posts

Blog Categories