473,396 Members | 1,816 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.

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 23 '05 #1
1 14981


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 23 '05 #2

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...
2
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...
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" ?>') ;...
4
by: Stephen | last post by:
I need to generate input XML for another application by serialising classes defined in an XSD document. The code below will generate the XML I require but I need to generate this in memory rather...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
0
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,...
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
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...

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.