Find And Replace Inside An XML File With XSLT
Join the DZone community and get the full member experience.Join For Free
// description of your code here //This XSL will search inside certain nodes of a given XML file //for certain values and replace them. //In my example I have a UnitOfMeasure node that contains "EA" or "FT" but I want to change //the EA to 1 and the FT to 0. //Also in my ObsoleteIndicator node I want to replace OBS with 1 and this other value I don't care about, //DNR to empty string to basically remove it. //So we end up with the exact same XML we started with just with those values translated. //You could do the same with regular string.replace but it would be very slow for large XML files //as it would have to visit every character in the entire file each time you called it (in my case // four times.)
Opinions expressed by DZone contributors are their own.