Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Generate XML from XMLDocument

From: Martin Honnen <mahotrash@-----.-->
To: NULL
Date: 2/3/2005 12:56:00 PM

brad@k... 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/


transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent