How to use the regular and php functions to replace the contents of all xml file tags with the same content, but multiplied by 32? It is necessary to import goods in Woocommerce, and there is the price in dollars. If there is a solution for js, then I will not refuse either.

  • But does js know how to overwrite files? - user33274
  • not able) stupidly) - Homie
  • many items? - user33274
  • more than 1600 prices need to be changed - Homie
  • I'm sorry of course ... but better on freelancing .. or wait .. can anyone do - user33274

1 answer 1

Using the built-in parser in JS

var xmldoc, parser, xmlroot; var rawxmldoc = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+ "<root>"+ "<price>"+ "200"+ "</price>"+ "<price>"+ "536"+ "</price>"+ "</root>"; parser = new DOMParser(); xmldoc = parser.parseFromString(rawxmldoc,"text/xml"); xmlroot = xmldoc.getElementsByTagName("root")[0]; for (var i = 0; i < xmldoc.getElementsByTagName("price").length; i++) { xmlroot.getElementsByTagName("price")[i].innerHTML *= 32; console.log(xmldoc.getElementsByTagName("price")[i].innerHTML); }