CDATA Mapping Experience inside BizTalk

XML CDATA is something I was not really familiar with before. Xml parsers normally parse all text in an xml document. Text inside a CDATA section is ignored. This week I stumbled over CDATA sections inside a message. This message I had to map to another message with a different structure and later on had to be passed to a web service. During mapping I seem to have lost the CDATA Section. I googled around, but I could not find a satisfactory solution to my problem. So I started experimenting with inline xslt and c# inside a script functoid. Unfortunately I had no result. I got CDATA section around data, but <> translated into ;lt and ;gt when I opened the resulting message inside notepad (when I temporarily saved it to file). In the end I got fed up with it and called a function inside a class module. I created a component (class library) with the class module and passed the mapped message as xml document to function I created. The function is listed below:

public XmlDocument AddCDataSection(XmlDocument xmlDoc)
{
XmlNodeList xmlNodeList = xmlDoc.DocumentElement.SelectNodes(xpathquery);

foreach (XmlNode node in xmlNodeList)
{
string x = node.InnerText;
string lang = String.Empty;
if (node.Attributes["lang"] != null)
{

lang = node.Attributes["lang"].InnerText;

}

node.InnerText = string.Empty;
node.AppendChild(xmlDoc.CreateCDataSection(x));
XmlAttribute att = xmlDoc.CreateAttribute("lang");
att.Value = lang;

node.Attributes.Append(att);

}

return xmlDoc;
}

The returned document I copied back into a new message inside a message assign shape. This gave me the desired result. Maybe there is a better way of mapping inside BizTalk with CDATA Sections. If anybody knows a better solution to CDATA Section and mapping I am happy to hear about it.

Technorati:

Comments

pandu@biztalk said…
Hi,
what is xpathquery ? in
this line.
XmlNodeList xmlNodeList = xmlDoc.DocumentElement.SelectNodes(xpathquery)
if you have class library please mail me the same on biztalkserver@yahoo.com
thanks
Anonymous said…
I have been exploring for a bit for any high quality articles or
blog posts in this sort of house . Exploring in Yahoo I finally stumbled upon
this website ().
Reading this info So i'm glad to exhibit that
I've an incredibly excellent uncanny feeling I discovered
just what I needed. I such a lot indisputably will make sure to don?t omit this site and give it a look regularly.
Nandu said…
What is xpathquery?

Popular posts from this blog

DTAP Strategy: Pricing and Licensing

Table Operation on Oracle 11g XE with OracleDbBinding

Integration, the community blasting into 2017!