无法在IE7中将XML元素附加到DOM中

时间:2017-02-27 22:45:30

标签: javascript jquery html xml internet-explorer-7

<xml>元素是IE7中的保留元素吗?我似乎不是appendChild这个元素或者在这个元素中。

DOM正在显示 -

<xml XMLDocument="[object]"></xml>

我需要在IE7中的DOM中附加<xml>元素才能触发POS系统中的特定功能。有没有办法逃避这个或为IE7做这个,我只能使用.text.innerText,但这不适用于我的情况,因为该函数查找XML元素而不是字符串。

预期结果 - 此结果来自Chrome和最新的IE。 enter image description here

使用vanilla javascript:

&#13;
&#13;
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.parse(jObj[item].Product)); // JSON.parse() older IE json2.js
            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);
&#13;
&#13;
&#13;

甚至是jQuery

&#13;
&#13;
var jObj = {"Smart Shoes":{"Product":"Smart Shoes","Price":24.99,"Quantity":"1x "},"Denim Jeans":{"Product":"Denim Jeans","Price":30,"Quantity":"1x "}}
    var xmlString = '<xml id="POSCMD" LateProcessing="true"><commands><injectfieldmacro type="field" name="FIELD_CLEAR"/>';

    for (var item in jObj) {
      if (jObj.hasOwnProperty(item)) {
        xmlString += '<injectdata type="literal" data="' + jObj[item].Price + '"/>'; // I don't know where you got UPC from
        xmlString += '<injectfieldmacro type="field" name="FIELD_UPC"/>'
      }
    }

    xmlString += '</commands></xml>';
&#13;
&#13;
&#13;

0 个答案:

没有答案