473,396 Members | 2,109 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.

Using JavaScript(?) to save an XML file

I am working on a project that will locally create XML files. I have an HTML form that uses the Dojo Toolkit and XSLT to create the XML object. Currently I put the XML into a textarea. The used must then copy the XML and paste it into an XML file. I would like for this step to be skipped (i.e. have the XML file created/saved without copying and pasting.)

My idea was to use JavaScript to open a new window, write the XML to that window, and then the user could save the page as an XML file, but the problem with that is either a) the XML tags are not rendered in the new window, or b) when the new window is saved it includes HTML tags.

Does anyone know how I can save the XML to an XML file? Ideally I would just have a button on the original page that would create and save it, but for security reasons I don't think the browser will allow this. Two important constraints are 1) all of the code must be client-side, and 2) the page must work in IE and FireFox. Any ideas?
Oct 17 '07 #1
7 15452
acoder
16,027 Expert Mod 8TB
Unfortunately, this is not going to work with standard JavaScript.

Is this for a restricted user environment where you could decide which browsers the users use?
Oct 18 '07 #2
Unfortunately, this is not going to work with standard JavaScript.

Is this for a restricted user environment where you could decide which browsers the users use?
Not really. The idea behind the project was that it would be cross-platform/cross-browser compatible, which rules out Active-x and FF extensions.
Oct 18 '07 #3
acoder
16,027 Expert Mod 8TB
Two important constraints are 1) all of the code must be client-side, and 2) the page must work in IE and FireFox. Any ideas?
Why must all the code be client-side?
Oct 18 '07 #4
Why must all the code be client-side?
That is just one of the requirements that I have been given. As of right now the all of the HTML, JS, XSL, etc. files will be distributed to the users instead of being hosted on a site. Sounds kinda odd, but that's what they want.

I just don't understand why I can open an XML document in a browser, but I can't write XML tags to a child window and save the contents of that window as an XML file. That just doesn't make any sense.
Oct 19 '07 #5
gits
5,390 Expert Mod 4TB
hi ...

you can write to a document in a browser window, but you cannot save anything (may be you could use the save page as menupotion?)... besides a cookie. this does make sense ... imagine a webpage that is able to save things at a client-machine ... may be malicious things ... nobody really wants that ... its a simple security issue. with (standard) javascript you cannot and you should not break out of the browser ...

kind regards
Oct 19 '07 #6
hi ...

you can write to a document in a browser window, but you cannot save anything (may be you could use the save page as menupotion?)... besides a cookie. this does make sense ... imagine a webpage that is able to save things at a client-machine ... may be malicious things ... nobody really wants that ... its a simple security issue. with (standard) javascript you cannot and you should not break out of the browser ...

kind regards
Oh, I completely understand the issue with automatically saving something; I intended to require the users to use the Save Page As menu option. The problem I am having is when I write XML to the child window the XML tags do not display. Here are two methods that I have tried in JS:

Expand|Select|Wrap|Line Numbers
  1. function test(){
  2.     mywin = window.open('text/xml','', 'menubar=1,scrollbars=2,resizeable=1');
  3.     mywin.document.open;
  4.     mywin.opener = self;
  5.     XML_txt = '<tool attrib="now">text inside XML "tool" tag</tool>';
  6.     mywin.document.write(XML_txt);
  7.     }        
  8.  

Expand|Select|Wrap|Line Numbers
  1.  var childWin = null;
  2.  function launchChildW() {
  3.    if (childWin != null) childWin.window.close();
  4.  
  5.    wopts  = 'width=300,height=500,scrollbars=1';
  6.    childWin = window.open('', 'childW', wopts);
  7.  
  8.    if (childWin != null) {
  9.      childWin.document.open()
  10.      if (childWin.opener == null) {
  11.        childWin.opener = self;
  12.      }
  13.    } else {
  14.        alert("Failed to open child window");
  15.    }
  16.    XML_txt = '<tool attrib="now">text inside XML "tool" tag</tool>';
  17.    childWin.document.writeln(XML_txt);
  18.  }
  19.  
Both of those functions will open a new window. The text within the XML tags gets displayed, but the XML tags do not. The other problem is, when I go to 'Save As' the new window, it saves all the code from the original page - not what is in the new window.

By the way, thanks everyone who has replied to these posts.
Oct 19 '07 #7
the browser is intepreting your xml as tags you need to escape them using html entities &lt;tool ...&gt; i think that will help with showing the xml tags.
Nov 6 '10 #8

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

Similar topics

6
by: Mike | last post by:
can i open the save file dialog box from a asp.net web page? thx
4
by: Jonny | last post by:
Hello Group How do I open a Save File Dialog from an ASPX page behind a browse button? Any help would be fantastic!! I am using ASP.NET 1.1 using VB.NET as the coding language TIA
3
by: jiayanxiang | last post by:
Is there any sample code to use Javascript to load and display a text file? It will be best if the user can select files using some kind of explorer. If that's complex, a text box to specify the...
8
by: ronen.chen | last post by:
I noticed that some sites use <script src='fineName.js?ver=XXX'></script(even google) Someone told me that it's for script changes, means - if the file in server has been changed than the new XXX...
0
by: pbd22 | last post by:
Hi. I am having a really tough time here and would appreciate some help. i am using an iFrame to pass a url string of files to upload to server. on the client i have created a multiple...
1
by: =?Utf-8?B?amVmZjMwNDg=?= | last post by:
Hi, I want to incorporate a JavaScript routine (found on the internet) in my page that will restore the scrollbar position of a div tag on postback. I am using master pages which complicates...
3
by: jaikant | last post by:
Hi, I am loading a xml file using javascript in Pocket Internet Explorer for local HTML file. I am not able to save the xml file back to the PPC device. foodXML = new...
4
by: Rakhi | last post by:
hello i want to alter the download settings of mozilla firefox browser using javascript of my application !! wat is happenin in my application is, on calling a method , it make a file ready...
1
colinod
by: colinod | last post by:
Is there a way of having an mp3 file save when you click on a button using javascript, i want to get rid of the need for a right click save as on my website?
7
by: saadkhan | last post by:
Is there any way to create xml file and save it in SQL Server database all using javascript? I have no security issues for the purpose i need to do it. Though if anyone could give me some better idea...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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.