views:

586

answers:

1

I'm creating an XML Document in javascript on the client side, and then transforming it back to a string to send to the server. Mozilla has a handy method to accomplish this: XMLSerializer().serializeToString(), which I'm using. However, there seems to be a bug in this method: it returns all node names in uppercase and all attribute names in lowercase(regardless of the capitalization I used to create the node).

Is there any way to circumvent this behavior and get back the XML string with my original capitalization? More generally, is there any way to create an XML Document in Mozilla and return it to a string without having your capitalization overridden?

+4  A: 

It looks like you are working with an HTML document. Try operating on XML document instead.

var oDocument = new DOMParser().parseFromString("<root />", "text/xml"); oDocument.documentElement.appendChild(oDocument.createElementNS("http://myns", "x:test")); alert(new XMLSerializer().serializeToString(oDocument));

or

var oDocument = document.implementation.createDocument("", "", null); oDocument.appendChild(oDocument.createElementNS("http://myns", "x:test")); alert(new XMLSerializer().serializeToString(oDocument));

Regards

Sergey Ilinsky