How to replace all &, <, > in string before parsing to XElement?
问题 I have string like this "<root><text>My test is > & < </text></root>" Actually this is correct xml, except &, <, > symbols. I need to convert it to <root><text>My test is > & < </text></root> before I convert it with XElement.Parse(str); How to make this conversion? 回答1: This is nigh-on impossible to achieve reliably. You should correct this issue at source. If you control the system that is inserting the "My test is > & < " string, then you should escape this string before inserting it.