I am trying to load an XML file, but the content in the XML has ampersands in it. Is there a way to escape them in the code? Rather than editing the actual XML file? All the other answers I have found have suggested that I edit the code before I load it with Javascript, but that is not an option for me because I am pulling it from a database that is always changing.
Any help would be appreciated.
From what I get from you question is that you want to replace the ampersands? If so I actually just dealt with this issue the other day.
The way I approached it was I loaded the XML File, then I took the
response.Text, which converts the XML file object into a string, and encoded that into hex. I then replaced all “%26”, which is the hex for “&”, with “&_amp;” (Take out the underscore! the message converts it into a ‘&’), which XML can understand. I then decoded it and loaded it again as a string. That’s all you have to do. Here is some sample code…