I am trying to add an attribute into an xml node. I have created the following function
function AddAttribute(xmlNode, attrname, attrvalue, path) {
var attr;
if (isIE())
attr = xmlNode.ownerDocument.createNode(2, attrname, "http://mydomain/MyNameSpace");
else
attr = xmlNode.ownerDocument.createAttributeNS("http://mydomain/MyNameSpace", attrname);
attr.nodeValue = attrvalue;
var n = xmlNode.selectSingleNode(path);
n.setAttributeNode(attr);
}
This code does not work in Firefox . It adds the node, but it does not add the namespace. I have tried in IE and in Chrome and it works fine.
Do you know how can I add the namespace? Or do you know any other alternative to create an attribute with a namespace?
Thanks
attrname?if (xmlNode.ownerDocument.createAttributeNS), that would make you independent from browser sniffing.