473,396 Members | 1,809 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Reading data from user-submitted XML file.

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,

Sincerely,

L.
Oct 28 '08 #1
7 3826
L. Ximenes wrote on 28 okt 2008 in comp.lang.javascript:
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?
<input type='file'is an uploading process.

Under normal security settings a browser cannot and should not read files
from the own client computer.

Your quest can greatly benifit from a serverside solution, as I point out
in my response to your other posting.

In IE, HTA instead of HTML could do the job too, I suppose,
but only on your own machine, not via the web.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Oct 28 '08 #2
L. Ximenes schreef:
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

>
Sincerely,

L.

--
"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
Oct 28 '08 #3
Erwin Moller wrote on 28 okt 2008 in comp.lang.javascript:
But I would always do this serverside. Powerful languages exist that can
make this easy for you (eg PHP, Perl).
Serverside Javascript being such powerful language, toch, Erwin?

The OP just needs to port his clientside solution to the server, with minor
adjustments.

And he stays being on topic in this NG as an additional bonus. ;-)

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Oct 28 '08 #4
Evertjan. schreef:
Erwin Moller wrote on 28 okt 2008 in comp.lang.javascript:
>But I would always do this serverside. Powerful languages exist that can
make this easy for you (eg PHP, Perl).

Serverside Javascript being such powerful language, toch, Erwin?
Absolutely Evertjan,

At least, that is what I heard (from you amongst others).
Personally, I never wrote 1 line of serverside JavaScript. I prefer PHP
or Java (and hate Perl).
>
The OP just needs to port his clientside solution to the server, with minor
adjustments.

And he stays being on topic in this NG as an additional bonus. ;-)
OK, but didn't you like my absurd suggestion: roundtrip to the server,
and then import it via XHR back to the JavaScript on the client? ;-)

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
Oct 28 '08 #5
Erwin Moller wrote on 28 okt 2008 in comp.lang.javascript:
Evertjan. schreef:
>Erwin Moller wrote on 28 okt 2008 in comp.lang.javascript:
>>But I would always do this serverside. Powerful languages exist that
can make this easy for you (eg PHP, Perl).

Serverside Javascript being such powerful language, toch, Erwin?

Absolutely Evertjan,

At least, that is what I heard (from you amongst others).
Personally, I never wrote 1 line of serverside JavaScript. I prefer
PHP or Java (and hate Perl).
It is very easy, if you are used to ASP and javascript.

Even the porting and repeating of functions that do not need special
browser [DOM, etc] or server support is nice.

checking for an acceptable form input can be repeated client and
serverside by just using exactly the same function on both sides.
>The OP just needs to port his clientside solution to the server, with
minor adjustments.

And he stays being on topic in this NG as an additional bonus. ;-)

OK, but didn't you like my absurd suggestion: roundtrip to the server,
and then import it via XHR back to the JavaScript on the client? ;-)
Certainly in general.

But why not process these data serverside,
forgoing the OP's stated cross-browser problem?

Especially if the javascript code is already available to the OP.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Oct 28 '08 #6
L. Ximenes wrote:
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,
Security restrictions usually prevent you from accessing local files
(file://) from remote resources (http(s):// or another non-file URI).
There are ways to work around that, but those are not interoperable.
They tend to be considered security bugs by vendors, so they have been "fixed".

However, if your application is running on the local filesystem, it may be
possible to make an emulated HTTP request using the file's URI to get its
file's content. In MSHTML, you need to use the
ActiveXObject("Microsoft.XMLHTTP") constructor call instead of the
XMLHttpRequest() constructor call for this to work.
or would I need the user to upload the file and subsequently read the
data from it?
AFAIK, that is the interoperable approach that always works. It should be
possible to use that as a fallback mechanism for the XHR approach.
PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
Oct 28 '08 #7
On Oct 28, 3:05*am, "L. Ximenes" <theosko...@gmail.comwrote:
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,

Sincerely,
You could put a textarea and ask the user to copy-paste the xml's text
into it ?

--
Jorge.
Oct 28 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: ^CeFoS^ | last post by:
Hello to everybody, I've done an application that draws in a frame the trajectory of a robot. The robot position is readed through the serial port, and several commands are wrote through the...
0
by: Mario Fischer | last post by:
Hi! I wrote a small SQL-parser for SELECT-statements for the purpose of easier switching between databases. The parser also works with multiple-table-queries. Until here everything is fine, but...
1
by: Andrew Banks | last post by:
I've got the following code in a control and the reader doesn't seem to be working. The connection details are correct. Any ideas? I am reading data from this database to log the user and a lot...
6
by: Peter | last post by:
I'm interested to know what ideas are out there for reading a parallel port at a constant sample rate while still allowing the user to interact with the GUI. That is, reading it every 10ms for...
6
by: Camper Joe | last post by:
Here's my code: Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim db As New SqlConnection Dim strSQL As String = "SELECT * FROM users WHERE strUsername = '" &...
4
by: J.D. | last post by:
Hello, I am working on a client project and they have a connection to a catalog system that passes data back and forth as xml over http The format of the data is as follow(s) > <?xml...
2
by: Toco | last post by:
Hello. I have app written in C# that we are testing. The executable is shared on our network. The method we are testing is a call to a foxpro table. The call is made to query the table, then...
10
by: Stephen Plotnick | last post by:
I've started some code but do not know how to get the anwser. Here is the code: I need the first four characters of data in a field (TextName) to get a name from a DB and put the name back into...
3
by: Sir Psycho | last post by:
Hi, For some reason, when i step over this code, it returns the full byte stream im expecting from the server, however when I let it run with no intervention, it only seems to grab a small chunk...
4
by: Claire | last post by:
Hi, I'm writing an internal mail system module for my project. There may be several thousand 'users' on site, and I need the whole list for filtering, so I decided to load up the users in the main...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.