p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   XML (http://p2p.wrox.com/forumdisplay.php?f=91)
-   -   Access is denied" load a simple xml file (http://p2p.wrox.com/showthread.php?t=24520)

nana January 26th, 2005 01:31 AM

Access is denied" load a simple xml file
 
Hi there,

Javascript will give me a pop-up error "Access is denied" when i try to load a simple xml file, which is in the server machine itself. The script is within a JSP page. I am running it with IE6 from an windows administrative acc straight on the server so there shouldn't be any access prob.

Code is something like that:

<script language="javascript>
var xml = new ActiveXObject("Microsoft.XMLDOM");
xml.async = false;
xml.load("C:/Documents and Settings/test.xml)

// upon the load statement; javascript will prompt error and jsp dies off

</script>

Another question i wanna ask, can i run the xml file at client side using the same javascript coding like above?

Hope u guys can help me.
Thanks in advance.


joefawcett January 26th, 2005 05:13 AM

You are trying to access a local file which will only be allowed if the site is in "Trusted Sites" or "Local Intranet" and you allow scripting of activex not marked safe.

The fact that the client is also the server is irrelevant.

The code would also work in a standard set up provided the same security settings were applied.


--

Joe (Microsoft MVP - XML)

Kalpakavalli.S February 17th, 2005 02:00 AM

actually i too have encountered a very similar problem. I had to use a round about way to cater the "Access Denied".

In Xmldom activex there are two functions to load xml

1) Load method to load a xml from a file, the string passed as a parameter is a filename along with path

2) LoadXML method to load a xml data directly by storing in string

The first method gives the "Access denied" problem so i tried to use the second method which did work

The javascript code is as follows, as you are already using an activex control i think you can use one more in teh same code FSO - File System Object

<script language="javascript>

var fsoXML = new ActiveXObject("Scripting.FileSystemObject");
var XMLFile = fsoXML.OpenTextFile(("C:/Documents and Settings/test.xml",1);
var Data = XMLFile.ReadAll();
XMLFile.Close();

var xml = new ActiveXObject("Microsoft.XMLDOM");
xml.async = false;
xml.loadXML(Data);

// upon the load statement; javascript will prompt error and jsp dies off

</script>


Please check the code, it will surely work


Valli

anand_asv February 24th, 2005 11:22 AM

i had a very similar problem in writing the xml file from asp.net application,This is happenning because of locking the system while writing the xml file in the drive.To Overcome that just create a folder and and place the file hence with.....


gabi4 January 7th, 2006 09:03 AM

hello!
that code doesn't work
do you have a solution for mozilla?


naeembhatti January 25th, 2006 03:10 AM

hi Kalpakavalli.S
it is not working even that it is giving me error of javascript that "object expect" i think due to

var fsoXML = new ActiveXObject("Scripting.FileSystemObject");


<script language="javascript>

var fsoXML = new ActiveXObject("Scripting.FileSystemObject");
var XMLFile = fsoXML.OpenTextFile(("C:/Documents and Settings/test.xml",1);
var Data = XMLFile.ReadAll();
XMLFile.Close();

var xml = new ActiveXObject("Microsoft.XMLDOM");
xml.async = false;
xml.loadXML(Data);

give some nice solution here.



thuffam May 17th, 2006 05:00 AM

I've had a similar problem occur - however it is not consistent...

Originally I had some structured JS code that worked fine (loading xml docs from localhost and from external sites).

Then I updated most of the code to be more OO - except the xml loading code. And now it only loads xml files on localhost. When attempting to load anything external and I get an "Access is denied" error.

Any ideas why?

All the code that does the load and retrieval of values from the xml files has not changed - and it works when calling it from very basic structured JS - eg poplist() (where poplist is a function that does the load and populates a list with the data in the xml file).

However when I call it from my new objects it can load local xml files - just not external ones.

Any help will be very much appreciated!
Thanks in advance
Tim Huffam


solanki_21 May 24th, 2006 05:18 AM

Hi friends
I 've also faced the same prob..
Wat i did, just trying to fetch an xml file from external source, it was giving me the Javascript error "Access is denied".
The solution of the above Problem is

Just change ur Browser Internet settings
if u are using IE then
click on Tools -> Options -> Security -> Custom Level -> Micsellaneous ->Access Data Sources across Domains -> Prompt.

Then click on "OK" ..


and refresh page and try again....

I hope it will run


Benny_A June 19th, 2007 10:22 AM

Quote:

quote:Just change ur Browser Internet settings
if u are using IE then
click on Tools -> Options -> Security -> Custom Level -> Micsellaneous ->Access Data Sources across Domains -> Prompt.

Then click on "OK" ..
That's all fine and dandy, works like you said it would. However, I'm trying to embed an rss feed into my site for my users to view. I can't expect every single one of them to go and modify their IE security settings.

There's gotta be a way to "Access data sources across domains" via the script...right?

Any ideas?

Benny_A
----------
Are you not entertAIn3d?

joefawcett June 19th, 2007 10:37 AM

The only way is to use a server-side proxy that relays the requests from your server to the real server. Cross domain access is only forbidden on the client, servers have free reign.

--

Joe (Microsoft MVP - XML)


All times are GMT -4. The time now is 05:45 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.