Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Generate XML from XMLDocument

Reply
Thread Tools

Generate XML from XMLDocument

 
 
brad@koehn.com
Guest
Posts: n/a
 
      02-02-2005
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?

 
Reply With Quote
 
 
 
 
Paul R
Guest
Posts: n/a
 
      02-03-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) 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).
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      02-03-2005


(E-Mail Removed) 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/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to generate XML file as follow, using XmlDocument. Abhijit D. Babar XML 0 05-21-2008 03:27 AM
Generate XML from XMLDocument brad@koehn.com Javascript 1 02-03-2005 11:55 AM
Re: Can an XmlNode from one XmlDocument be copied to another XmlDocument? Bob ASP .Net 0 07-21-2004 11:49 PM
ASP XML Support - Generate XML string from FORM DATA based on XML schema Matt ASP General 3 04-23-2004 07:12 PM
loading xmlcontent from one xmldocument into another xmldocument Shoval Tomer ASP .Net 0 07-09-2003 04:29 PM



Advertisments