Either DOMParser or XMLSerializer is dropping my namespace declaration in IE9

前端 未结 2 507
天涯浪人
天涯浪人 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 = '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:n0="web5540"></soap:Envelope>';
    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 = "<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" ><n0:GetSales /></soap:Envelope>"
    

    ... I end up doing this ...

    var r = '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"></soap:Envelope>';
    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 = "<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><n0:GetSales xmlns:n0="web5540" /></soap:Envelope>"
    

    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.

    0 讨论(0)
  • 2021-01-13 16:57

    I made a test case http://home.arcor.de/martin.honnen/javascript/2012/test2012070901.html and I can confirm that the output with IE 9 on Windows 7 is

    Input
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:foo="http://example.com/foo">
    <xsl:template match="foo:bar">Test</xsl:template>
    </xsl:stylesheet>
    Output
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:template match="foo:bar">Test</xsl:template>
    </xsl:stylesheet>
    

    so the namespace declaration is dropped. I consider that a bug in IE 9, you might want to check connect.microsoft.com whether anything like that is already reported, and if not file it. Is anyone reading here using IE 10? What does IE 10 show?

    [edit]There is a connect issue on IE 10, probably related: https://connect.microsoft.com/IE/feedback/details/728093/xmlserializer-omits-xmlns-attributes.

    0 讨论(0)
提交回复
热议问题