I created the following HTML file to test your function and get the
following errors:

1)  The file input element returns only the file's name, so I don't
see how your function could load the file in.

2) Under Safari 3 and later, I get a "TypeError: Result of expression
'xmlDoc.load' [undefined] is not a function." when your function
attempts to call xmlDoc.load()

3) Your function always returns null, under Firefox 3.0.8 and Safari 4
beta, presumably because it only has a file name, not the file path.
It does appear to work under Opera 9.51.  [all under OS X 10.5.6]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <title>Load File</title>
    <meta http-equiv="Content-Type" content="text/html;
    <script src="../prototype.js"></script>
    function loadXMLFile(fileName) {
  var xmlDoc;
  // W3C compliant
  if (document && document.implementation &&
      document.implementation.createDocument ) {
    xmlDoc = document.implementation.createDocument("","",null);
  } else {
    // IE model
    try {
      xmlDoc = new ActiveXObject('Msxml2.DOMDocument');
    } catch( e){}
  if (xmlDoc) {
    xmlDoc.async = false;
    try {
      var loadOK = xmlDoc.load(fileName);
    } catch(e) {
  return loadOK? xmlDoc : null;

function doLoadFile() {
    var doc = loadXMLFile($F($("fileName")));
      <h1>Load File</h1>
      <input type="button" value="Load" name="load" onclick='doLoadFile
()' />
      <input type="file" id='fileName' name="fileName" value=""
width="50" />

RobG wrote:
> On Apr 14, 3:11 pm, Doug Reeder <reeder...@gmail.com> wrote:
> > I'd like to allow the user to select a file from his/her filesystem,  
> > and process it locally.  Due to heightened security (or at least the  
> > semblance thereof) the value of a file input element is just the name  
> > of the file, not the full path, in many modern browsers, so the file  
> > path can't be turned into a "file:" URL that can be loaded via AJAX.    
> > Is there a way to access the contents of the file using Prototype?
> Nothing to do with AJAX (where AJAX is a pseudonym for
> xmlHttpRequest).  If it's an XML document, it can be loaded using a
> fairly simple script:
> --
> Rob
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to