Either DOMParser or XMLSerializer is dropping my namespace declaration in IE9

前端 未结 2 526
天涯浪人
天涯浪人 2021-01-13 16:33

So I think there are probably cleaner solutions than what I am doing anyway, but I\'m wondering if this is a known issue, if there\'s something obvious I\'m doing wrong, etc

2条回答
  •  滥情空心
    2021-01-13 16:55

    I was also experiencing this issue. In IE11, I had some javascript serializing XML and the namespace URI's were being dropped.

    As a workaround I used the createElementNS method when creating the appropriate child node.

    So for example, instead of ...

    var r = '';
    var m = new DOMParser().parseFromString(r, "text/xml");
    var n = m.createElement('n0:GetSales');
    var p = m.firstChild;
    p.appendChild(n);
    var k = new XMLSerializer().serializeToString(m);
    // In IE, k = ""
    

    ... I end up doing this ...

    var r = '';
    var m = new DOMParser().parseFromString(r, "text/xml");
    var n = m.createElementNS('web5540', 'n0:GetSales');
    var p = m.firstChild;
    p.appendChild(n);
    var k = new XMLSerializer().serializeToString(m);
    // In IE, k = ""
    

    I am not sure this would help in the original case, as the DOMParser would be doing all of the element creation, but I decide to post in case someone else is having a similar issue.

提交回复
热议问题