Try this. Not sure whether it could help.
1. Place the MusicXML file to the same path of the wav file
2. Select the item that you wanna replace
3. Make sure you have installed SWS
Code:
reaper.Undo_BeginBlock()
local it=reaper.GetSelectedMediaItem(0, 0)
local tk=reaper.GetActiveTake(it)
local _, chunk=reaper.GetItemStateChunk(it, '', 1)
local path=chunk:match('FILE \"([^\"]+)\"')
local fn_noext=path:match(".+[/\\](.+)%.%w+$")
local fn_new=fn_noext..'.musicxml'
reaper.BR_SetTakeSourceFromFile(tk, fn_new, true)
reaper.Main_OnCommand(40441, 0)
reaper.UpdateArrange()
reaper.Undo_EndBlock('MusicXML', -1)