Inject XML tags into a JavaScript string at specified indices.