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

Generate XML from XMLDocument

I have an XMLDocument that my web page downloads and manipulates as a
response to user input. I have lots of JavaScript that acts as a
controller between my view (html) and my model (xml). That works fine.

Once the user's done editing, I want to send the modified XMLDocument
back up to my server (as XML). The problem is, I can't find a way to
use JavaScript to generate XML from an XMLDocument. Is there some
obvious API that I'm missing? I assume there's more than one way to do
it (one way for IE and one way for Mozilla, who knows how many others),
anybody want to share?

Jul 20 '05 #1
2 5048
br**@koehn.com wrote:
I have an XMLDocument that my web page downloads and manipulates as a
response to user input. I have lots of JavaScript that acts as a
controller between my view (html) and my model (xml). That works fine.

Once the user's done editing, I want to send the modified XMLDocument
back up to my server (as XML). The problem is, I can't find a way to
use JavaScript to generate XML from an XMLDocument. Is there some
obvious API that I'm missing? I assume there's more than one way to do
it (one way for IE and one way for Mozilla, who knows how many others),
anybody want to share?


You could send the XML file direct using an XMLHttpRequest object
(Mozilla and IE, although they may differ a little).

Alternatively, write the XML text to a hidden (HTML) field using the
[DOMDocument].xml property (IE) or an XMLSerializer object (Mozilla).
Jul 20 '05 #2


br**@koehn.com wrote:
I have an XMLDocument that my web page downloads and manipulates as a
response to user input. I have lots of JavaScript that acts as a
controller between my view (html) and my model (xml). That works fine.

Once the user's done editing, I want to send the modified XMLDocument
back up to my server (as XML). The problem is, I can't find a way to
use JavaScript to generate XML from an XMLDocument. Is there some
obvious API that I'm missing?


I think so, XMLHttpRequest in Mozilla browsers (Mozilla suite, Firefox,
Netscape 6/7), in latest Safari and Konqueror, and Microsoft.XMLHTTP in
IE 5/5.5/6 on Windows simply lets you pass in your XML document as a
parameter to the send method e.g.
var httpRequest;
if (typeof XMLHttpRequest != 'undefined') {
httpRequest = new XMLHttpRequest();
}
else if (typeof ActiveXObject != 'undefined') {
httpRequest = new ActiveXObject('Microsoft.XMLHTTP');
}
if (httpRequest) {
httpRequest.open('POST', 'XMLLoader.asp', true);
httpRequest.onreadystatechange = function (evt) {
if (httpRequest.readyState == 4) {
if (httpRequest.status == 200) {
// process response here e.g.
// process httpRequest.responseXML
}
else .... handle other response status if needed
}
};
httpRequest.send(xmlDocument);
}

See
<http://www.faqts.com/knowledge_base/view.phtml/aid/17226/fid/616>
for details.

If you need to serialize an XML document to a string (that is not needed
for the above, XMLHttpRequest's send method simply needs the document
object) then with MSXML there is the property named xml for DOM nodes thus
var xmlString = xmlDocument.xml;
gives you the serialized XML as a string, with Mozilla you have
XMLSerializer e.g.
var xmlString = new XMLSerializer().serializeToString(xmlDocument);
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #3

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

Similar topics

1
by: Tim:. | last post by:
Hi Can someone tell me how I generate a new XML file that I can then use with an XSLT file. I am trying to use an XML file generated from Microsoft Project or even better generate an XML file from...
5
by: Dario de Judicibus | last post by:
I am trying to generate an XML file to be shown in IE by javascript. My code looks like top.x = window.open('','MyXML') ; top.x.document.write('<?xml version="1.0" encoding="ISO-8859-1" ?>') ;...
1
by: brad | last post by:
I have an XMLDocument that my web page downloads and manipulates as a response to user input. I have lots of JavaScript that acts as a controller between my view (html) and my model (xml). That...
1
by: Ryan | last post by:
Can anyone point me to some examples of generating a complete XmlDocument given an XmlSchema object?
5
by: skidz | last post by:
I am trying to write an application that will generate XSL files (trying to automat some of my development), but am having a heck of a time. I just don't fully grasp the namespace issues I am...
2
by: Blair Chen | last post by:
Pls help me out I am trying to generate xml file via XmlDocument class. I ceated a XmlDocument instance, how can I convert it to a physical xml file(e.g. test.xml)? following is the code: //add...
0
by: taylorjonl | last post by:
I am having a problem generating some soap proxies dynamically using almost the exact same code as in the MSDN sample. ...
1
by: Abhijit D. Babar | last post by:
Hello, I have to generate XML file as follow, using XmlDocument. <Company> < Employee EID=”111” Description=” xyz”> <Dept DeptNo=”D10”> <FirstNameAbhijit </FirstName> <LastNameBabar...
0
by: Abhijit D. Babar | last post by:
Hello, I have to generate XML file as follow, using XmlDocument. <Company> < Employee EID=”111” Description=” xyz”> <Dept DeptNo=”D10”> <FirstNameAbhijit </FirstName> <LastNameBabar...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
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.