L. Ximenes schreef:
Quote:
Hello everyone,
>
I know how to parse data from an XML file with Javascript; but what if
I would like to parse data from a user-submitted XML file via the "
<input type='file'"? Would it be possible to read directly from that
file, or would I need the user to upload the file and subsequently
read the data from it? In any case, what would be the best and cleaner
way to do it?
I thank you in advance for any insight on this,
Hi,
You'll have to do this serverside.
If you want to read a file on the clients machine, JavaScript cannot
access it under most circumstances.
Maybe it is possible to lower securitysettings in IE to such a low level
it is allowed, I am not sure if that is possible.
(Just imagine how safe your computer would be if any webpage could
access files on your computer via JavaScript.)
If you REALLY want to do the parsing clientside with JavaScript, you
could use the following round-trip:
1) Upload the file to the server.
2) Server places the file in a place where it is accessible via http.
3) Let JavaScript get the file in (using AJAX eg) from that location.
4) Do the parsing in JavaScript.
But I would always do this serverside. Powerful languages exist that can
make this easy for you (eg PHP, Perl).
Regards,
Erwin Moller
--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare