Jaa


Changing an XML Response to an HTML output using a Map

 

Recently, I was working on a BizTalk Server solution where I received an XML response that was supposed to go out on an e-mail. Well, there’s no big deal about it.. just route the XML response to the SMTP port. But there was another requirement, I wanted the XML response to be stripped of all XML tags and be in a legible format, just like any other e-mail.

To give you a slightly better understanding, let’s look at the schema of the XML response.

image

If the response message is sent to the SMTP port, as-is, the resultant e-mail would have a plethora of XML tags, making the e-mail very difficult to read. So, to make the e-mail legible, I could use some code to strip the tags and just have the values within the tags being displayed as text. The other option was to use a map. Here’s how. Assuming that the e-mail will be an HTML document, I created a schema that depicted a typical HTML document schema, which is:

<html>
  <body>
    <p></p>
    ….
    …. 
  </body>
</html>

To translate this into XML schema, it would look like:

image

The above schema contains one para tag. You can have any number of para tags as you want, depending on how you want your e-mail output to look. In my solution, I only wanted to have the <element> in the XML response message mapped to the <p> element in the HTML schema. The map would look like:

image

So, now when the e-mail goes out, it would contain the value within the text tag as separate paragraph lines on the e-mail. Just one thing still remains, and that is to change the text encoding. In my case, I did this as part of the message construct shaped that called the map. The expression reads like this:

OutputResponse(Microsoft.XLANGs.BaseTypes.ContentType) = "text/html";

where, OutputResponse is the schema for the HTML e-mail output.