473,385 Members | 1,400 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,385 software developers and data experts.

Javascript to import xml file

I am trying to create a javascript bookmarklet to import an xml file that is located on my pc. While I have found numerous examples of code that is part of a web page, I cannot get it to work as a bookmarklet.

The debug alerts are displaed until xmlDoc.load is called and then no error messages or anything else. This is running in Firefox 1.5.09 on windows 2000.

Any suggestions?

Expand|Select|Wrap|Line Numbers
  1. javascript:function%20loadXML()
  2. {
  3.     var dbug = 1; 
  4.     var xmlfile = "c:\test.xml"; 
  5.     var xmlDoc; 
  6.     function import_xml(file) 
  7.     {
  8.         if (dbug) alert('ImportXML'); 
  9.         var xmlDoc; var moz = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined'); 
  10.         var ie = (typeof window.ActiveXObject != 'undefined'); 
  11.         if (moz) 
  12.         {
  13.             xmlDoc = document.implementation.createDocument("", "", null); 
  14.             xmlDoc.onload = parse_xml;
  15.         } 
  16.         else if (ie) 
  17.         {
  18.             xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); 
  19.             xmlDoc.async = false;  
  20.             while(xmlDoc.readyState != 4) {}; 
  21.         }
  22.         if (dbug) alert('Load');
  23.         xmlDoc.load(file);
  24.         if (dbug) alert('Loaded');
  25.     }
  26.     function parse_xml() 
  27.     {
  28.         if (dbug) alert('parseXML');
  29.     }
  30.     if (dbug) alert('loadXML'); 
  31.     import_xml(xmlfile);
  32. }loadXML();void(null)
  33.  
Feb 9 '07 #1
1 4686
acoder
16,027 Expert Mod 8TB
Two points: when testing for object detection, just use e.g.
Expand|Select|Wrap|Line Numbers
  1. if (window.ActiveXObject) // ie
Secondly, in Firefox, etc. you cannot access local files (security hole in IE).

See this page for an example of loading XML via AJAX.
Feb 12 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

22
by: Weston C | last post by:
I know of course that you can use <script src=""></script> in an HTML document to include javascript code you don't want to spill all over the page. I'm wondering if there's a way to include...
25
by: Jeff | last post by:
Use the MS Script Editor included free with MS Office 2002 and above, for debugging Internet Explorer (IE). This subject is of great interest to many JS developers, as there is no obvious, low...
9
by: Trenqo 0 | last post by:
I'm looking for a way to include javascript files from within a ".js" file. This would allow me to only need to link to one ".js" file, and yet still organize my functions into non gargantuan files...
3
by: Casper Hornstrup | last post by:
I have an ASP.NET application that imports product descriptions from an Excel file. The Excel file is uploaded, then a background thread will start importing the product descriptions from the Excel...
1
by: Joseph Scoccimaro | last post by:
I am using greasemonkey to create a script that allows one to analyze a web page. Currently I am trying to import the javascript from an external file to add to the DOM of a web page. It is...
1
by: elsheh | last post by:
Hi. Guys I use an XSLT style sheet to transform my xml document into html doc. I need to embed an external JavaScript file into html doc. The following line is used for this purpose: <script...
2
by: neeebs | last post by:
Hi, I'm not sure if this is a javascript problem per se, but here goes. I have an xsl document with a python function defined within a <script> block. Elsewhere in the xsl file, within a python...
2
by: ManidipSengupta | last post by:
Hi, a few (3) questions for the Java experts, and let me know if this is the right forum. It deals with 100% java code (reason for posting here) but manages a Web browser with Javascript. Thanks in...
2
by: JohnLorac | last post by:
Hello, I'm trying to load and write file on local disc drive using signed javascript file. But I have experienced problem running this url: ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.