我正在使用我在SO
上找到的这个功能function serializeXmlNode(xmlNode) {
if (typeof window.XMLSerializer != "undefined") {
return (new window.XMLSerializer()).serializeToString(xmlNode);
} else if (typeof xmlNode.xml != "undefined") {
return xmlNode.xml;
}
return "";
}
我尝试在我的代码中使用它:
var doc = parser.parseFromString(mattes_get_mattes_xml(), "application/xml"); //convert the string to xml
doc.getElementsByTagName('fillet')[index].innerHTML = "<imgsrc>" + thumb + "</imgsrc><width>" + width + "</width><cid>" + cid + "</cid><sku>" + sku + "</sku>";
console.log(doc.getElementsByTagName('fillet')[index].innerHTML);
//var serializer = new XMLSerializer(); //create a new XMLSerializer
//mattes_mattes_xml = serializer.serializeToString(doc); //convert the xml back to a string
mattes_mattes_xml = serializeXmlNode(doc);
console.log(mattes_mattes_xml);
common_get_order_xml();
moulding_draw(img, "fillet", selected_matte); //Call the moulding_draw function, which draws the fillet on the canvas
我console.log(doc.getElementsByTagName('fillet')[index].innerHTML);
的第一个输出给了我<imgsrc>113a2584b32539ecdc35d70b39fde504</imgsrc><width>0.31</width><cid>9352</cid><sku>TD00060S1</sku>
。
console.log(mattes_mattes_xml);
的第二项输出给了我<Mats><mat><item size="0"><imgsrc>478374fede4b2625708c5b4f71fb5e53</imgsrc><size>0</size><cpu>20</cpu><cid>4180</cid></item><fillet /></mat><mat><item size="0.5"><imgsrc>3a546c35f4fc21a748769e1f15bcdac5</imgsrc><size>0.5</size><cpu>0</cpu><cid>4460</cid></item><fillet /></mat><mat><item size="0.5"><imgsrc>556e832bb85e3887c3597a67defbb100</imgsrc><size>0.5</size><cpu>0</cpu><cid>4117</cid></item><fillet /></mat></Mats>
- 它遗漏了<fillet>
IE版本是11。
答案 0 :(得分:0)
var fillet_xml = "<imgsrc>" + thumb + "</imgsrc><width>" + width + "</width><cid>" + cid + "</cid><sku>" + sku + "</sku>";
mattes_mattes_xml = mattes_get_mattes_xml().replace("<fillet></fillet>", "<fillet>" + fillet_xml + "</fillet>");
console.log(mattes_mattes_xml);
common_get_order_xml();
moulding_draw(img, "fillet", selected_matte); //Call the moulding_draw function, which draws the fillet on the canvas
如果有更好的方法,我想知道......