I need to consume XML based RESTful API. All request are sent in XML format. I've been using MooTools extensions to build XML requests. However, I don't know how to transform it string, so that I could send the XML directly to server.
var reqEl = new Element('req');
var loginEl = new Element('login');
var usernameEl = new Element('username',{text: login});
var hashEl = new Element('hash', {text: pass});
loginEl.inject(usernameEl);
loginEl.inject(hashEl);
reqEl.inject(loginEl);
This code generates following XML:
<req>
<login>
<username>peter123</username>
<hash>123abc</hash>
</login>
</req>
Is there any way the element object to string? Or should I always build XML requests manually? Something like this:
var q = "<req><login><username>" + escape(login) + "</username><hash>" + pass + "</hash></login></req>";
Thanks in advance!