1

Our app has a weird requirement which is to construct an xml using javascript and send that back to server as string.

I tried with jquery like this

$xmlT = $("<?xml version=\"1.0\" encoding=\"utf-8\"?><root></root>");

            $root = $("<notebook></notebook>"); //.attr("title", roottitle).            
            $root.attr("title", title);
            $root.attr("id", id);


            $root.appendTo($xmlT);

but am not able to get the xml as string back from the above variable.

is there some way or library using which i can construct xml and access that as string?

Regards, Jeez

3 Answers 3

1

You can do things like createElement() etc on the XMLDoc returned from XMLHttpRequest.responseXML

http://www.w3schools.com/dom/dom_nodes_create.asp

So perhaps you can use XMLHttpRequest without actually doing a request, so you can get an object to manipulate.

You could then serialise the XML Dom using the XMLSerializer (for firefox) or xmlNode.xml for IE (metioned here How do I serialize a DOM to XML text, using JavaScript, in a cross browser way?)

Sign up to request clarification or add additional context in comments.

Comments

0

You could take a look at this plugin

1 Comment

thanks for the reference but i was looking for plugin which would work the other way
0

I found these jquery plugins xml2json & json2xml which is close to what I was looking for, if not the same.

For more info check stackoverflow entryXML <-> JSON conversion in Javascript

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.