Question

I have the following schema:

<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://www.RedEyedMonster.co.uk/Integration/ESB" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" elementFormDefault="qualified" targetNamespace="http://www.RedEyedMonster.co.uk/Integration/ESB" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:annotation>
    <xs:appinfo>
      <b:schemaInfo is_envelope="no" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" />
    </xs:appinfo>
  </xs:annotation>
  <xs:element name="ExternalEvent">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="1" maxOccurs="1" name="XmlType" type="xs:string" />
        <xs:element minOccurs="1" maxOccurs="1" name="EscXml" type="xs:string" />
       </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

Where EscXml contains escaped XML which can be quite complex. Is it possible to convert this in a map (i.e. unescape) to an node or to the schema that will be derived from XmlType?

Was it helpful?

Solution

Applying this stylesheet:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="*[local-name()='EscXml']">
    <xsl:copy>
        <xsl:value-of select="." disable-output-escaping="yes"/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

To this sample document:

<ExternalEvent xmlns="http://www.RedEyedMonster.co.uk/Integration/ESB">
<XmlType>Testing1Two6</XmlType>
<EscXml>&lt;!--  Edited by XMLSpy&#174;  --&gt;
&lt;note&gt;
&lt;to&gt;Tove&lt;/to&gt;
&lt;from&gt;Jani&lt;/from&gt;
&lt;heading&gt;Reminder&lt;/heading&gt;
&lt;body&gt;Don&apos;t forget me this weekend!&lt;/body&gt;
&lt;/note&gt;</EscXml>
</ExternalEvent>

Gives me the following result – also in BizTalk:

<?xml version="1.0" encoding="UTF-8"?>
<ExternalEvent xmlns="http://www.RedEyedMonster.co.uk/Integration/ESB">
   <XmlType>Testing1Two6</XmlType>
   <EscXml>

      <!--  Edited by XMLSpy®  -->
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

   </EscXml>
</ExternalEvent>

Hope this helps :]

OTHER TIPS

I see there being two general options for you to manipulate the contents of the EscXML.

Option 1

In a map, you could build a functoid or use a scripting functoid backed by a custom assembly which would receive the content of the xml as a parameter. The method would then have to unescape the provided XML and you could use something like XDocument, xpath statements or similar to parse and update the contents as you needed. The method could then escape the XML and return it back to the mapper.

This way is going to be fairly memory intensive and not really all that flexible since you will have to do all of your message manipulation in code.

Option 2

If your message is passing through an orchestration, you can do some work there to extract the content of your EscXML, unescape it and then assign it to a message variable based in the XmlType. From there, you would be able to leverage the mapper, etc. Once you were done there, you could escape it again and stuff it back into your wrapped message.

Since you can stream in this scenario, you it should be less memory intensive (for message creation) and you would also be able to use the mapper, etc. The biggest caveat here is that you would need an orchestration to perform this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top