So I’m getting data from a 3rd party in the form of an XML String.
I want to then do the following
messageString = Encoding.ASCII.GetString(messageBeingSent);
messageString = messageString.Trim();
XDocument xmlDoc = XDocument.Parse(messageString);
However, it errors out and gives me the exception
hexadecimal value 0x00 is an invalid character. Line 1, Position x where X is the last character in the string.
This appears to me that a null terminator is being sent along with the string and then the XDocument flips out because of the null terminator.
What’s the solution to this?
null character is not valid in XML.
You can pass characters you want to trim: