473,797 Members | 2,970 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3841
L. Ximenes wrote on 28 okt 2008 in comp.lang.javas cript:
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 securitysetting s 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.javas cript:
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.javas cript:
>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.javas cript:
Evertjan. schreef:
>Erwin Moller wrote on 28 okt 2008 in comp.lang.javas cript:
>>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.XMLHT TP") 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...@gma il.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
9094
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 same port to change the direction of the robot. The trajectory frame is managed by an applet, and the project works good when the applet is called by a html document allocated in the same local machine under W98 where the classes and the serial port...
0
1625
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 when I try to read out the information from flatfiles I get in trouble. An example: I'm reading all columns of 2 tables and I want to search for something defined in the WHERE-statement. For example I want to manage user-sessions in a...
1
1278
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 of the details are the same. public class AdminNavigation : System.Web.UI.UserControl {
6
3279
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 example without exception. Is this at all possible? Current tests done show that if the sample rate is 10ms then this is acheived in general, but when another program loads or terminates this 10ms jumps up to 100ms or more. In these tests the code is...
6
1413
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 = '" & txtUsername.Text & "'" Dim ds1 As DataSet = New DataSet() db.ConnectionString = "Data Source=.\SQLExpress;Integrated
4
1409
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 version="1.0"?> > > <customer-redemption>
2
2172
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 fill a datable with the resultset. All is fine when I run the executable from my machine. However, when our test user runsthe same executable, the app errors out when attempting to read from the foxpro table. I have logged where the user...
10
3957
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 TextName. Dim conn As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data source=C:\BMActivityReporting.mdb;Persist Security Info=False")
3
6774
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 on the stream. What am I doing wrong? There is more code than this, but this is the problem code.
4
2018
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 form of the module in a background thread I used to read in this list the first time it was required, but as there's usually a "dead" period between opening the main form and actually needing the list it seemed a good idea to do it this way to...
0
9685
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9536
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10468
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10245
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10205
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10021
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9063
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7559
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4131
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.