Link to home
Start Free TrialLog in
Avatar of eladr
eladr

asked on

From stream to (xml) string problem with chars\encoding

Hi,
i getting stream message (from biztalk) in this case, convert it to string and load it to xmldocument.
im getting data at root level is invalid.
when i debug the code, i can see there are chars (???? question marks) beside the xml like:

--------------------------
Invalid at the top level of the document. Error processing resource 'file:///C:/Documents and Settings/eladro/Local Setting...

??<
^
-------------------------
how it can be solved??
thanks.

this is my simple code:
----------------------------------------------
IBaseMessagePart bodyPart = inmsg.BodyPart;
System.IO.Stream originalStrm = bodyPart.GetOriginalDataStream();

byte[] buffer = new byte[originalStrm.Length];
originalStrm.Read(buffer, 0, Convert.ToInt32(originalStrm.Length));
XMLData = System.Text.ASCIIEncoding.ASCII.GetString(buffer);

XmlDocument xmldoc = new XmlDocument();
xmldoc.LoadXml(XMLData);
----------------------------------------------
Avatar of kjetilroe
kjetilroe
Flag of Norway image


Are you sure that the encoding is ASCII, and not UTF-8?

I know that those codes usually describe what encoding the string is in, and usually XML is encoded in UTF-8.

System.Text.Encoding.UTF8.GetString(buffer);

Hope this helps.

Kjetil
Avatar of eladr
eladr

ASKER

same error...
ASKER CERTIFIED SOLUTION
Avatar of kjetilroe
kjetilroe
Flag of Norway image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of eladr

ASKER

10x