Thursday, September 13, 2012

Problem with LoadXml in BizTalk

I ran into a problem where an XML was written to flat file but instead of the flat file containing one line of data, it contained multiple lines. Or in other words: there were unwanted line-breaks in the line.

It took me a while to figure out where they came from, but finally I found this: I had an input string containing the XML like this:


In BizTalk inside an expression shape, I had code like this:

someMessage = xdoc;

Here someMessage contained:


So <node> contained a line-break...

The solution was simple: set PreserveWhitespace to true like this:

xdoc.PreserveWhitespace = true;
someMessage = xdoc;

Thanks to Scott Colestock's blog I found this.

BTW When the input XML was like this:

<root><node /></root>
the problem never occured...