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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML DOM object load function 1

Status
Not open for further replies.

atisman89

Programmer
Jan 15, 2007
7
US
Hi, this may look like a basic question but...
Can the XML DOM object load an xml file in any arbitray URL? I have a Javascript that creates a DOM object and I'd like to use load function with a URL that indicates an XML file... For example, using Firefox...

...
xmlDoc=document.implementation.createDocument("","",null);
xmlDoc.load("...

I'm running a WEBrick webserver in my local PC and running the script but it doesn't seem to work. But it can load any XML files in my local PC. Any explanation why this happens would be appreciated.
Thank you.
 
Before the load line, add this line to consent for the access to another domain.
[tt]
//etc...
xmlDoc=document.implementation.createDocument("","",null);
[blue]netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead")[/blue]
xmlDoc.load("//...etc
[/tt]
 
Thank you for your reply, tsuji.
I tried as you suggested. But I had no luck with getting it work. Any other idea/suggestion? Does it work in your browser? I tired with IE 6.0 with no luck either. Looks like that the function "netscape.security.PrivilegeManager.enablePrivilege" is for FireFox. Do you know any equivalent function that I can use in IE?
 
Sure the device is for moz/nn/ff, it is _not_ for ie. But you said For example, using Firefox... and those lines are for ff as well. Whether the load function support http protocol, I know it does. What is the problem? And do not test moz=specific lines on ie or vice versa, it won't help.
 
Of course, I have tried with the FireFox first but it didn't work. It still couln't load the xml file in the specified URL. I was asking if there is any equivalent function in IE so that I can try it in IE also.
 
I don't need to try to know the script for ie is not the same as for moz/ff/nn. The two lines you shown is for moz/ff/nn no problem. The problem is how to get result from the xmlDoc which is again using different script lines from ie. That is why I ask how do you know it does not work. Adding the security manager line will take out the permission problem. But, you still have to know the proper way to handle the xmlDoc object to get result out of it. So ... what are the lines below? I know it works but I want you to know your conclusion is unwarranted, because you mess the unshown lines.
 
The site I showed you has a complete JavaScript for IE. I just took an example. I need my script to work for both FF and IE. But just let us forget about FF for now. I'd like to get the code in the following site work in IE:


Do you have any suggestion? Thank you help again!
 
I don't go there not because I don't trust the site, but only that I don't necessarily trust any site.

Here is how you go about, at last I don't have that kind of time to turn about a thing round and round.
[tt]
<script language="javascript">
function doit() {
if (document.implementation && document.implementation.createDocument) {
var oxmldoc=document.implementation.createDocument("","",null);
oxmldoc.async=false;
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead")
oxmldoc.load(" alert(new XMLSerializer().serializeToString(oxmldoc));
} else if (window.ActiveXObject) {
var oxmldoc=new ActiveXObject("msxml2.domdocument")
oxmldoc.async=false;
oxmldoc.load(" alert(oxmldoc.xml);
}
</script>
[/tt]
Do you know sufficient to get the meaning of what I show?
 
Thank you for your detailed reply, tsuji, I tried out your code exactly in the html as following in "IE". It didn't show any message box with the XML source string, which we should expect. Instead, I got the error mark at the left bottom corner of my IE browser. When I double-clicked it, it said: ... Error: Access is denied ...
You don't need to reply to this message if you don't want to spend your time on this topic any more. Thank you anyway.

Here is how I used your code:
------------------------------

<html>
<head>
<script language="javascript">
function doit() {
if (document.implementation && document.implementation.createDocument) {
var oxmldoc=document.implementation.createDocument("","",null);
oxmldoc.async=false;
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead")
oxmldoc.load(" alert(new XMLSerializer().serializeToString(oxmldoc));
} else if (window.ActiveXObject) {
var oxmldoc=new ActiveXObject("msxml2.domdocument")
oxmldoc.async=false;
oxmldoc.load(" alert(oxmldoc.xml);
}

}

</script>
</head>

<body onload="doit()">

</body>
</html>
 
I missed a closing bracket and I see you add it back. That's the right thing to do.

It is only related to the security-zone setting of ie. It doesn't mean load has any problem. Check internet zone and change to prompt rather than disable the use of activex not marked as safe. Another direction is to put the site into trusted list (I am not necessarily recommended it). In any case, if you do not get it, check out the help file of ie on the security and privacy. That has nothing to do with the functionality. Worse to worse, google issues related to ie security setting.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top