Solved

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

707 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

15 Experts available now in Live!

Get 1:1 Help Now