I've been using the new $.parseXML()
method with jQuery 1.5. Whenever I insert a new element into the XML object, that new element automatically gets the 'xmlns' attribute with the value "http://www.w3.org/1999/xhtml". For example, see the code snippet below:
var myXml = "<one attr='a'><two attr='b'/><three attr='c'><four attr='d'/></three></one>";
myXml = $.parseXML(myXml);
$(myXml).find('three').append($('<five>some value</five>'));
The code creates the following element:
<five xmlns="http://www.w3.org/1999/xhtml">some value</five>
How do I prevent jQuery from inserting the 'xmlns' attribute? I've tried using the .removeAttr()
method, but not even that seems to work. Any ideas?
UPDATE:
The suggestion that user nrabinowitz offered was helpful in solving this problem. Adding an xlmns attribute to the top level element does prevent the xlmns attribute from getting automatically assigned to each new element. Still, I opted for another solution for my particular program. I instead used the .replace()
method to remove all the xlmns attributes after after I converted the XML object back into a string (to be displayed on a web page).