Solved

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

Posted on 2007-11-29
4
380 Views
Last Modified: 2008-02-01
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);
----------------------------------------------
0
Comment
Question by:eladr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 4

Expert Comment

by:kjetilroe
ID: 20372395

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
0
 
LVL 1

Author Comment

by:eladr
ID: 20372410
same error...
0
 
LVL 4

Accepted Solution

by:
kjetilroe earned 85 total points
ID: 20372579
First of all:

The BizTalk server defaults to encoding the xml to UTF-8, unless you have overridden that setting in your BizTalk server.

Ok, another solution:

Why dont you take the stream right into your xml document like this:

XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(originalStrm);

Kjetil
0
 
LVL 1

Author Comment

by:eladr
ID: 20372662
10x
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question