0

I am receiving a standard XML document inside an any tag. Currently I simply copy the entire document received an insert it inside the any tag as shown in the XSLT below:

      <xsl:element name="msgBody">
        <xsl:copy>
          <xsl:copy-of select="/" />
        </xsl:copy>
      </xsl:element>

This works as intended in that it inserts the XML document where the any tag is placed in the schema. However this needs to be sent to an SQL database using the WCF-SQL adapter. Therefore I need to unescpae the XML, since the < > characters are being interpreted by the adapter, which throws an error like this:

"The start element with name X and namespace X was unexpected. Please ensure that your input XML conforms to the schema for the operation."

The any tag is set to skip xml processing. I understand that there's an option to disable output escaping on the value-of element, but how can I achieve this using the copy-of element? Will I instead need to implement a pipeline to handle the escaping?

In short, I want an XML string like this:

<bizSaveDocument>
    <conversationID>829c0747-76e0-4298-a9f1-0fcc2a234668</conversationID>
    <fromID>NULL</fromID>
    <toID>NULL</toID>
</bizSaveDocument>

To be escaped, so that the output of the map becomes this:

&lt;bizSaveDocument&gt;
    &lt;conversationID&gt;829c0747-76e0-4298-a9f1-0fcc2a234668&lt;/conversationID&gt;
    &lt;fromID&gt;NULL&lt;/fromID&gt;
    &lt;toID&gt;NULL&lt;/toID&gt;
&lt;/bizSaveDocument&gt;
Leth
  • 1,033
  • 3
  • 15
  • 40
  • Funny, I've just had the same problem. This might be helpful https://stackoverflow.com/questions/1162352/converting-xml-to-escaped-text-in-xslt – helcim Dec 13 '18 at 12:22
  • Thanks, I tried the solution but it generates a lot of unnessacary namespaces, as the author also describes. Do you know a way to remove these namespaces from the output? – Leth Dec 13 '18 at 12:49
  • What about this one https://stackoverflow.com/questions/5268182/how-to-remove-namespaces-from-xml-using-xslt – helcim Dec 13 '18 at 12:52
  • This seems a bit unusual. Are you trying to Sent the Xml as a string? Or will you be using OpenXml (don't ;) on it? Basically, what will you be doing with the Xml once it hits the SP? – Johns-305 Dec 13 '18 at 13:16
  • The XML should be stored on a record in the database in a single field. Yes I am trying to send the XML as a string, since it will not be processed or validated in any way. – Leth Dec 13 '18 at 13:19

1 Answers1

1

You have to use some small custom Xslt for this.

It's been explained in this Blog: Convert xml file to string inside BizTalk map using inline XSLT

Note, this technique uses a CDATA section which is technical the same as escaping.

If you really want it escaped, you can remove the disable-output-escaping attribute and CDATA section. (Disclosure: This is how I remember it working, I haven't done this in a while :)

Johns-305
  • 10,908
  • 12
  • 21