Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I prevent jQuery from inserting the 'xmlns' attribute in an XML object?

Tags:

People also ask

How do I get rid of xmlns?

Open the map in the Design Studio. Edit the output card in question (in this case output card 1 of the validationMap map) and expand it so you can right click on Property > Schema > Type > Metadata > Name Spaces > http://www.example.com/IPO. After right clicking on http://www.example.com/IPO, left click on Delete.

What is the purpose of xmlns attribute?

The xmlns attribute specifies the xml namespace for a document. Note: The xmlns attribute is required in XHTML, invalid in HTML 4.01, and optional in HTML5. Note: The HTML validator at http://w3.org does not complain when the xmlns attribute is missing in an XHTML document.


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).