Solved

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

Posted on 2007-11-29
4
374 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

863 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now