473,799 Members | 3,134 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 15007


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.XMLHT TP 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.XMLHT TP');
}
if (httpRequest) {
httpRequest.ope n('POST', 'XMLLoader.asp' , true);
httpRequest.onr eadystatechange = function (evt) {
if (httpRequest.re adyState == 4) {
if (httpRequest.st atus == 200) {
// process response here e.g.
// process httpRequest.res ponseXML
}
else .... handle other response status if needed
}
};
httpRequest.sen d(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() .serializeToStr ing(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
2346
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 the project file (MPP File) itself. Which I can then use with an XSLT file I am new to XML and want to create a project viewer using XML, ASP and XHTML. I have an idea of how this should work but would really appritiate any help someone can...
2
5067
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 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?...
5
2004
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" ?>') ; top.x.document.write('<myxml>') ; // all the other write's top.x.document.write('</myxml>') ;
4
2081
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 than creating a file. I assume I should be using System.IO.MemoryStream but can't get this to work. ' XML will be serialized to file.xml, in UTF-8, with BOM. Dim tw As New System.Xml.XmlTextWriter( _ New System.IO.FileStream("file.xml",...
1
1738
by: Ryan | last post by:
Can anyone point me to some examples of generating a complete XmlDocument given an XmlSchema object?
5
2590
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 having. This is what I have so far: ---------------------------------Code XmlDocument doc = new XmlDocument(); doc.AppendChild(doc.CreateXmlDeclaration ("1.0","UTF-8", string.Empty)); XmlNode root = doc.AppendChild(doc.CreateElement
2
1308
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 root XmlElement rootNode = xmlDoc.CreateElement("root"); rootNode.SetAttribute("root", root); xmlDoc.AppendChild(rootNode);
0
2555
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. http://msdn2.microsoft.com/en-us/library/system.web.services.description.webreference(VS.80).aspx It has very few differences, mainly I had to manipulate the document to remove the Any tags that caused 400+ validation warnings but even after getting the WebReference object ValidationWarnings to 0, it says...
1
1543
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 </LastName> </Dept>
0
1271
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 </LastName> </Dept>
0
9688
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9546
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10491
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10031
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9079
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7571
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.