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.GetOriginalDataSt ream();
byte[] buffer = new byte[originalStrm.Length];
originalStrm.Read(buffer, 0, Convert.ToInt32(originalSt rm.Length) );
XMLData = System.Text.ASCIIEncoding. ASCII.GetS tring(buff er);
XmlDocument xmldoc = new XmlDocument();
xmldoc.LoadXml(XMLData);
-------------------------- ---------- ----------
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.GetOriginalDataSt
byte[] buffer = new byte[originalStrm.Length];
originalStrm.Read(buffer, 0, Convert.ToInt32(originalSt
XMLData = System.Text.ASCIIEncoding.
XmlDocument xmldoc = new XmlDocument();
xmldoc.LoadXml(XMLData);
--------------------------
ASKER
same error...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
10x
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.
Hope this helps.
Kjetil