Swapped the order of replacing references and decoding characters on inner text of xml nodes.