Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder
    Join Date
    May 2006
    Posts
    123
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Parsing *local* XML files in Javascript...Possible?

    Hi... I've been pulling my hair out here and I just want a simple answer.

    I want to use Javascript to parse an XML Document and grab a simple variable out of there to throw into a form input. The catch is that it's a LOCAL XML file, and I've been getting "Permission Denied" errors.

    Basically before I rip ALL my hair out I just want to know if it's even POSSIBLE to parse local XML files using client-side scripting or if I should just give up and go with server-side?

    It doesn't REALLY matter I guess, but I was hoping I could keep it all client side...

  • #2
    Regular Coder
    Join Date
    May 2006
    Posts
    123
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Just to be more specific, the exact line of code that's giving me problems is (yes I'm using Firefox)...:

    xmlDoc=document.implementation.createDocument("","",null);
    xmlDoc.async = false;
    xmlDoc.load(localPath);

    I just want a single variable out of an xml file that the user chooses to send me! I'm not going to do anything bad, honest!!

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Imagine you go to a webpage and it is capable of reading your local files........
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

  • #4
    Regular Coder
    Join Date
    May 2006
    Posts
    123
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes yes yes... I understand all that...

    But the thing is this isn't ANY local file... it's one that the user VOLUNTARILY INPUTS... this is the original REASON for the necessity of a type="file" input, no?

  • #5
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,048
    Thanks
    2
    Thanked 317 Times in 309 Posts
    The only purpose of the type="file" form field is to upload the file to the server. Here is the RFC that defines this - http://www.ietf.org/rfc/rfc1867.txt
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #6
    Regular Coder
    Join Date
    May 2006
    Posts
    123
    Thanks
    0
    Thanked 0 Times in 0 Posts
    So I take it that means "no, you can't do it?"

  • #7
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Actually, if you are using IE you can do it. I wrote this a loooong time ago for when I was working an internal help desk. At the end of each shift, we were required to send a list of the escalated issues we handled, and a brief description of each, to our manager. I created this page to make my life easier. When you launch the page, it looks for a folder on your local machine named, "esc_track". If it does not exist, the script creates it. If it does exist, the script looks through the folder for saved escalation "reports", to find the one for today. If no such file exists, it creates it. If one does exist, it reads the contents of the file and displays it in the text area. I'm sure you could adapt this for what you need. Just a reminder though, it's going to be IE only. As far as I know, this is simply not possible in Firefox.

    Link to the file, saved as text:
    http://tektips.us/track.txt

    Just a note, I wrote this a long time ago and the code ain't pretty. I know that there is likely many, many things that could be done to improve it...just never seemed to get around to doing it.

  • #8
    Regular Coder
    Join Date
    May 2006
    Posts
    123
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, if possible I'd like to make a cross-browser solution... not to mention the fact that I wouldn't really care to exploit a security hole just so that I can do something perfectly legitimate! I'm trying server-side solutions to this problem now, but I'm STILL pulling my hair out over security issues.

    Perhaps someone would like to suggest an alternate path I could follow based on what I want to do... it REALLY shouldn't be that difficult...

    All I want is to have a form in which you can enter (geographic) coordinates. If you know them, you can enter them yourself - if not, then you can upload (or let's say just "input"...depending on whether client-side scripting can be used for this) a Google Earth KML file. The file may as well be a text file...let me worry about the XML. I simply want a way to ACCESS this file so that I can parse it for the precious, precious coordinates inside! What I'm REALLY looking for is an inline solution ... in other words when the user chooses a file, the browser location stays put and the coordinates "pop" into the appropriate field. Sounds like a job for AJAX, but ajax doesn't support file uploading!

    I would very much appreciate an ELEGANT solution for this...

  • #9
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Try to look into signed javascript.

  • #10
    Regular Coder
    Join Date
    May 2006
    Posts
    123
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks... I'll have a look at this, but I think I'll probably end up going with passing variables back and forth between an iframe.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •