附加到DOM时,XML属性变为小写

时间:2017-03-01 13:42:31

标签: javascript jquery xml dom

有没有办法让XML attribute成为pascal case" LateProcessing"什么时候将XML附加到DOM中?下面的代码显示了属性LateProcessing="true"但是,一旦XML附加到DOM中,它就变成小写lateprocessing="true"



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>';

$('body').append(xmlString);
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
&#13;
&#13;
&#13;

enter image description here

1 个答案:

答案 0 :(得分:0)

这种情况正在发生,因为您正在尝试将XML添加到HTML DOM中。 HTML规范化元素名称的情况,而XML则不规范化。目前尚不清楚你为什么要这样做,所以我不能建议你应该做什么,我只能说这不是一件好事。

通过字符串连接构造词法XML然后解析它也不是好习惯。特别是如果您不尝试将转义应用于可能出现在变量字符串中的特殊字符,例如&<以及"