Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loading a remote XML file

Status
Not open for further replies.

BountyHunter2

Programmer
Feb 12, 2003
10
0
0
GB
Hi,

A newbie question i'm afraid. Why does the below not work when the xml file is on a remote server, but work if i download the file and host it on my server?

ps I need to do this client-side as ChiliSoft ASP doesn't support the MS XMLDOM object.

<html>
<body><script type=&quot;text/javascript&quot;>
// Load XML
//var xml = new ActiveXObject(&quot;Microsoft.XMLDOM&quot;)
var xml = new ActiveXObject(&quot;MSXML2.DOMDocument&quot;)
xml.async = false
xml.setProperty(&quot;ServerHTTPRequest&quot;, true)
alert(1)
xml.load(&quot;alert(2)

// Load XSL
var xsl = new ActiveXObject(&quot;Microsoft.XMLDOM&quot;)
xsl.async = false
xsl.load(&quot;cdcatalog.xsl&quot;)

// Transform
document.write(xml.transformNode(xsl))</script>

</body>
</html>
 
>> Why does the below not work

define not work do you get error messages?

-pete
 
No, there are no error messages.

I placed the alerts to see where the script reaches, and it doesn't reach alert(2) with means that the problem is with the load function.
 
This may not be ur problem but I can't get to that URL i receive a Unresolved Host Name error.

-pete
 
This could help, I am also a newbie but I notticed this in your code:

1.-There are no ; at the end of the javascript code, you should put an ; at the end of each sentence

2.- delete the last ; from the xml.load(&quot;URL here&quot;;), change it to xml.load(&quot;URL here&quot;); as this

xml.load(&quot;
I changed this at besides removing the alerts, the browser (IE6) only gave me an alert about that the contents the page was trying to display were insecure, and later, it said that the XML document could be malformed or something like it just couldn't display it

I hope this helps

bellow is the modified code I used

<html>
<body><script type=&quot;text/javascript&quot;>
// Load XML
var xml = new ActiveXObject(&quot;MSXML2.DOMDocument&quot;);
xml.async = false;
xml.setProperty(&quot;ServerHTTPRequest&quot;, true);
xml.load(&quot;
// Load XSL
var xsl = new ActiveXObject(&quot;Microsoft.XMLDOM&quot;);
xsl.async = false;
xsl.load(&quot;cdcatalog.xsl&quot;);

// Transform
document.write(xml.transformNode(xsl));

</script>

</body>
</html>
 
Still doesn't work i'm afraid!

The ;) instead of ); in the xml.load line was just a typographical error when copying and pasting.

is definitely a valid XML file. Like i said, if i save it locally the script works. It is only when the script tries to read the file from a different domain that it doesn't.
 
>> read the file from a different domain

oh i had no idea that's what ur doing. I don't believe that is not allowed for any kind of resource within script. Only HTML level resources can be cross domain. I think ur running into the sandbox.

Can anyone verify this?

-pete
 
Ok, there's an IE security setting &quot;Access data across domains&quot; which defaults to &quot;Disabled&quot;. If i enable it the script works, and the XML is processed.

... which is a pain as i have no control over the users client settings.

So i have to find another way to do it. As i said earlier Linux doesn't have the Microsoft XML objects, so i can't use ASP. Might have to resort to PHP in an <IFRAME> unless someone else can help!!!
 
>> Linux doesn't have the Microsoft XML objects

That does not mean you can't run server side code using XML DOM implementations, just a couple:

Java under JavaServlets
Apache C++ Xalan using CGI

-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top