I have a class decorated with XML attributes such as [XmlAttribute(“att”)]. My goal is to create an XDocument with this class’s xml. Everything works great except for a ‘0x1f’ character that occasionally enters the scene externally. So naturally I try to replace it like so:
XmlSerializer serializer = new XmlSerializer(this.GetType());
StringWriter sw = new StringWriter();
serializer.Serialize(sw, this);
string s = sw.ToString();
s = s.Replace((char)0x1F, ' ');
XDocument xs = XDocument.Parse(s);
return xs;
However I still get an error: “‘ ‘, hexadecimal value 0x1F, is an invalid character.”
Just for a sanity check, here’s a screenshot:
https://i.stack.imgur.com/rIos4.png
Any ideas where I could be going wrong?
You’ll get the same response if it’s represented as an entity – maybe that’s what’s happening? Look at
sto be sure.Sample: