I am working with an API and for some crazy reason the XML being returned has & characters that are not correctly escaped. This has left me in an annoying position. I get an exception when i try to use an XMLDocument
to parse the xml string.
I can use replace to get rid of the characters, but this could lead to issues.
xml = xml.Replace("&", "&").Replace("&", "&");
The problem with this is that there may end up being some escaped values. A node like this will cause the line of code above to get screwed up.
<node>Something & something < annoying</node>
If i replace the & characters with amp; it will break lt;. I cant use the same approach for lt; as i did for the amp as it will mean that it will convert all of the <> brackets that i still need to get escaped.
Here is a node that is giving trouble.
<CompanyName>Fire & Ice</CompanyName>