View Full Version : Import local XML file and create HTML table on the web
I'm trying to output an HTML page from a simple XML file, but I need to offer this as a service from a website, so users can browse and find the XML file on their local hard drives, and then generate an HTML page.
I think there are some security issues with HTTP not being able to access local files (ie. C:\temp.xml) because it doesn't work when I browse to a local file from the website (files on servers work fine). Is there any other way to pass an XML file from local to a website?
I'm using javascript to load the XML file.
Alex Vincent
10-07-2005, 03:55 AM
Generally that's not allowed, per the sandbox model of JavaScript. If you have a XUL chrome application, you might be able to do it.
KC-Luck
10-07-2005, 05:13 PM
they can send the XMLDOM to the server via XMLHttpRequest, and the server could use that DOM, or even the string of the DOM to perform the transform.
Alex Vincent
10-08-2005, 06:17 PM
But XMLHttpRequest can't get the XML file from the local file system.
KC-Luck
10-10-2005, 07:14 AM
it could if granted permission to do so :)
everyone, thanks for the replies.
KC-Luck, can you please tell me how to grant permission so that an XMLHttprequest can get a XML file from the local system?
KC-Luck
10-11-2005, 06:14 PM
really depends on the platforms and browser versions you are speaking, but requires the client to allow the interaction, ie in firefox, user is presented a dialog box to allow deny access to it, via netscape.security.enablePriv... blah.
with M$ you would simply open it. :)
<html>
<head>
<script type="text/javascript">
function go() {
var xml, localfile = document.getElementById("theFile").value;
if (window.ActiveXObject) {
xml = new ActiveXObject("Msxml.DOMDocument");
xml.async = false;
xml.resolveExternals = false;
xml.validateOnParse = false;
xml.load(localfile);
if (xml.parseError.errorCode != 0)
return echo(xml.parseError.reason);
} else if (document.implementation && document.implementation.createDocument) {
// the user gets a prompt to allow|deny
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
xml = document.implementation.createDocument('', '', 'text/xml');
xml.load(localfile);
// blah blah code code...
}
if (xml) echo(xml.documentElement.nodeName);
}
function echo(s) {
document.getElementById("response").innerHTML = s;
}
</script>
</head>
<body>
<input id="theFile" type="file"/>
<button onclick="go()">Go</button>
<div id="response"></div>
</body>
</html>
findorf
05-21-2007, 04:09 PM
Hi KC-Luck
I'm using FireFox 2.0.0.3 and keeps getting
uncaught exception: Et script fra "file://" blev nægtet UniversalBrowserRead privilegier
In english:
uncaught exception: A script from "file://" was denied UniversalBrowserRead privilege
I'm working on an internal (drawing) tool and is trying to make a small page that loads a xml file with the specefic users shortcut into the browser. The drawing tool itself supports only FireFox, so I'm only interested in the code for Mozilla/FireFox.
Best regards
Johannes Findorf
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.