Let's say that I have the following XML:
<someRootElement>
<someTagWithUrl>http://www.google.com/s.php&test=testing</someTagWithUrl>
</someRootElement>
The ampersand inside the someTagWithUrl is invalid and needs to be escaped (by using &
), but suppose I have a single string with the entire above contents.
How can I safely escape the ampersand so it becomes valid XML? Can .NET's XML library ignore this? (currently XElement.Parse will throw an exception)
I've thought about using a regular expression to search for ampersands between tags but I can't quite get the syntax correct. (something like >(\&)\< as a regex replace using & but I can't figure it out).