Quick Tip: How to control XML encoding in BizTalk Server 2004

A classic mistake in BizTalk is to think that you can control more than you really can through schemas.   For example, although you can specify default values within a schema (say for a attribute value), this has no effect on message construction and output.  Schemas are for validation, mapping, data-typing.etc.   They don't control message construction or value output.

A related issue that came up recently was how to control XML encoding.   BizTalk defaults to UTF-8 for XML encoding, and a client of ours had been trying to change this by modifying their XSDs.   This does not work.  You control XML encoding by using the XML assembler within the send pipeline .   By default, the XML Assembler outputs XML in UTF-8.    If you are using a bespoke pipeline, you can change this behaviour by simply setting the TargetCharset property of the XML Assembler component within Visual Studio.

If your outbound message passes through an orchestration, there is another approach you can use.  In your orchestration, simply introduce an expression shape before the message is sent, or use an appropriate existing message assignment shape and add the following XLANG/s code...

someMessage(XMLNorm.TargetCharset) = "UTF-16";

...where someMessage is an orchestration message object that contains the message you are sending.   This code will set a contextual property on the message that will tell the XML assembler to output UTF-16 rather than UTF-8.   You can use this approach with the 'built-in' XML send pipeline which already contains the XML assembler component.

This article is part of the GWB Archives. Original Author: Charles Young

New on Geeks with Blogs

  • We Won The One Award I Actually Care About

    Full Scale made the Inc. 5000 for the fifth year straight, the 12th listing across my three companies. Here is why the one award you cannot buy is worth stopping for.

  • Your Customers Build the Features Now

    I let a tool I liked sit dead for a year rather than build the features I wanted. An MCP server meant I never had to, and your customers can do the same to your product.

  • Get the Size of a Directory in Linux the Easy Way

    du -sh for the quick answer, ncdu for the cleanup, df for the disk itself: every command for checking directory size in Linux, plus why du and df never agree.

  • Vim Search and Replace: The Ultimate Guide

    One :%s command replaces every match in a file before a find dialog would even open. The Vim substitute patterns worth the muscle memory: flags, ranges, capture groups, and multi-file edits.