Mapping XML String in Biztalk Mapper to Destination

Monday, November 14, 2011
Hello All,
I am facing problem in mapping an element from source to destination.
I am polling data from a database which will trigger my process. In the receved message i have a field which has XML content. Based on the XML content i have to call a WCF service. I have a map that transforms the input message to the WCF request (simply by extracting the content of the XML element). But it seems it is not working.  My sample message is:
Here i need to extract the Xml element content in a map and assign that to destination. (Note the XML Content is the complete message for my destination). I have a scripting functoid which replaces the "&lt;" with "<" and "&gt;" with ">" and the output is connected to a another scripting functoid that maps the replaced content to the root node of the destination. But when i test the map in design time, the values are not getting replaced. I am not sure why this happens. Below is the code i used in the maps:
First scripting functoid:
 public string GetXml(string param)
param = param.Replace("&lt;","<");
param = param.Replace("&gt;",">");
return param;
Output of this is given to an XSLT Template of a scripting functoid:

<xsl:template name="TypedPollingResultSet0">
    <xsl:param name="param1" />
    <xsl:value-of select="$param1" />
Below is my map:


If you use any Orchestration then Just do this in an expression shape.

Create a variable xmlDoc of type System.Xml.XmlDocument.

varString = xpath(msgPollingResult,"string(/*[local-name()='Input' and namespace-uri()='']/*[local-name()='Xml' and namespace-uri()=''])");

//loads this to the string variable. "&lt;Add&gt;&lt;A&gt;10&lt;/A&gt;&lt;B&gt;10&lt;/B&gt;&lt;/Add&gt;";

varString = varString .Replace("&lt;", "<");

varString = varString .Replace("&gt;", ">");


msgAdd = xmlDoc; //msgAdd is your output.

If there are some namespaces that you have to change, use this msg as input to the map and modify it.

Else If you are Using a Messaging solution

How about creating a custom C# library and then using tat in the scripting functoid. For this you would need to GAC the assembly and use it in the map.

Note: use the above code in a C# Library Gac it and call the method in Biztalk Mapper


No comments:

Post a Comment

Post Your Comment...