?
Solved

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

Posted on 2007-11-29
4
Medium Priority
?
382 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 340 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

Technology Partners: 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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

800 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