jQuery converting XML tags to uppercase

I have a AJAX requests which returns a string of XML which I'd like to inject into the DOM. My function looks like

    type: 'POST',
    url: "myrequest",
    data: postdata,
    datatype: 'json',
    success: function (arguments) {
        newxmlstring = arguments.newxml;
        oldnode = $("someselector specified in the arguments passed");

This works but it appears that the replaceWith function maps all nodeName into capitalized versions of the response sent by the server. I'm assuming this is some quirk with trying to use jQuery to handle XML?

So for example if the response string is <data>asdf</data> when I access $(newnode)[0].nodeName I get 'DATA'.

Does anybody know how to handle the new XML while preserving the nodeName in lower case?

EDIT: My response is JSON since it contains the new xml string and a bit of other data about where to attach the new xml node. So I'd prefer to keep datatype: 'json' if at all possible.


From this answer:

In XML (and XML-based languages such as XHTML), tagName preserves case. In HTML, tagName returns the element name in the canonical uppercase form. The value of tagName is the same as that of nodeName.

A bit of searching shows that a lot of people experience this problem, especially with selectors and XML (jQuery's find() is case sensitive and selectors used in find() are lowercased).

Here's a function someone else is using to convert a string into XML that may work for you:

$.text2xml = function(sXML) { 
    // NOTE: I'd like to use jQuery for this, but jQuery makes all 
    // tags uppercase 
    //return $(xml)[0]; 
    var out; 
        var dXML = ($.browser.msie)?new ActiveXObject("Microsoft.XMLDOM"):new DOMParser(); 
        dXML.async = false; 
    }catch(e){ throw new Error("XML Parser could not be instantiated"); }; 
        if($.browser.msie) out = (dXML.loadXML(sXML))?dXML:false; 
        else out = dXML.parseFromString(sXML, "text/xml"); 
    catch(e){ throw new Error("Error parsing XML string"); }; 
    return out;

Need Your Help

Finding the 10001st Prime Number - Project Euler

javascript arrays primes

I am trying to find the 10,001th prime number. I have looked at other code people have written , but I don't really understand what it means. I have written some code in JavaScript in which I tried...

Java Class that extends String (or similar)

java class

This is mainly out of curiosity. How would you (if you can) make a class that mimics String. You can't extend String as it's final so that's a no go, but purely for the interest factor, I thought a...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.