I am using XmlDocument.Load to load the contents of an XML file that has some characters in Thai. The application is erroring out with the following exception.
System.Xml.XmlException: Invalid character in the given encoding. Line 2, position 82. at System.Xml.XmlTextReaderImpl.Throw(Exception e) at System.Xml.XmlTextReaderImpl.InvalidCharRecovery(Int32& bytesCount, Int32& charsCount) at System.Xml.XmlTextReaderImpl.GetChars(Int32 maxCharsCount) at System.Xml.XmlTextReaderImpl.ReadData() at System.Xml.XmlTextReaderImpl.ParseText(Int32& startPos, Int32& endPos, Int32& outOrChars) at System.Xml.XmlTextReaderImpl.FinishPartialValue() at System.Xml.XmlTextReaderImpl.get_Value() at System.Xml.XmlLoader.LoadNode(Boolean skipOverWhitespace) at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc) at System.Xml.XmlDocument.Load(XmlReader reader)
The XML file begins with this content
Notice the strange character before the closing tag. This content is coming from a third-party and I don't have access to the file/content.
My questions are:
- Why is the strange character appearing in the content sent to my from the third party provider?
- Is there any way to successfully process the file (load it into the XmlDocument) since I don't have access to modifying its content before processing it?