如何在IE7中将XML节点附加到HTML DOM

时间:2017-02-27 11:31:11

标签: javascript jquery html xml dom

我正在尝试将XML节点附加到IE< 8中的HTML DOM中,并且我不断收到Object doesn't support property or method appendChild错误,但在最新的浏览器上工作正常。是否有另一种在DOM中附加XML元素的方法?

我也尝试过<meta http-equiv="X-UA-Compatible" content="IE=8">

我想将XML元素附加为字符串,如下图所示。 enter image description here

var jObj = { "Smart Shoes":{  
          "Product":"Smart Shoes",
          "Price":24.99,
          "Quantity":"1x "
       },
       "Denim Jeans":{  
          "Product":"Denim Jeans",
          "Price":30,
          "Quantity":"1x "
       }
    };

    var xml = document.createElement("xml");
        xml.setAttribute("id", "POSCMD");
        xml.setAttribute("LateProcessing", "true");
        var commands = document.createElement("commands");
        xml.appendChild(commands);
        var injFM = document.createElement("injectfieldmacro");
        injFM.setAttribute("type", "field");
        injFM.setAttribute("name", "FIELD_CLEAR");
        commands.appendChild(injFM);
        var injData;
        for (var item in jObj) {
            injData = document.createElement("injectdata");
            injData.setAttribute("type", "literal");
            injData.setAttribute("data", JSON.stringify(jObj[item].Product));
            injFM = document.createElement("injectfieldmacro");
            injFM.setAttribute("type", "field");
            injFM.setAttribute("name", "FIELD_UPC");
            commands.appendChild(injData);
            commands.appendChild(injFM);
        }
        document.getElementsByTagName("body")[0].appendChild(xml);

0 个答案:

没有答案