cancel
Showing results for 
Search instead for 
Did you mean: 

Generate escape characters in the XML

Former Member
0 Kudos

Hi Guys,

I have requirement to generate the escape characters in the XML message:

My input  message:


<?xml version="1.0" encoding="UTF-8"?>

<SiebelMessage ErrorMessage="INVALID STATE/COUNTRY" ErrorCode="1020" MsgType="Cr" IntObjectFormat="Siebel Hierarchical" IntObjectName="HS" MessageType="Integration">

<ListOfServiceProvider>

<ServiceProvider>

<Id>1</Id>

<SAPVendorNumber/>

</ServiceProvider>

</ListOfServiceProvider>

</SiebelMessage>

Using XSLT mapping to generate SOAP wrapper:


<?xml version="1.0" encoding="UTF-8" ?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" xmlns:asi="http://siebel.com/asi/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">

  <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>

  <xsl:strip-space elements="*"/>

  <xsl:template match="/">

  <SOAP:Envelope>

  <soapenv:Header>

  <wsse:Security soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="0" xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/07/secext">

  <wsse:UsernameToken>

  <wsse:Username>O</wsse:Username>

  <wsse:Password Type="wsse:PasswordText">O</wsse:Password>

  </wsse:UsernameToken>

  </wsse:Security>

  </soapenv:Header>

  <soapenv:Body>

        <asi:HS1_spcGeneric_spcInbound_spcIntegration_spcWS_spcWrapper_Execute_Input>

  <asi:_XMLMessage>

  <xsl:copy-of select="." />

  </asi:_XMLMessage>

  </asi:HS1_spcGeneric_spcInbound_spcIntegration_spcWS_spcWrapper_Execute_Input>

    </soapenv:Body>

  </SOAP:Envelope>

  </xsl:template>

</xsl:stylesheet>

<

Output after executing above XSL:


<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" xmlns:asi="http://siebel.com/asi/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">

  <soapenv:Header>

    <wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/07/secext" soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="0">

      <wsse:UsernameToken>

        <wsse:Username>O</wsse:Username>

        <wsse:Password Type="wsse:PasswordText">O</wsse:Password>

      </wsse:UsernameToken>

    </wsse:Security>

  </soapenv:Header>

  <soapenv:Body>

    <asi:HS1_spcGeneric_spcInbound_spcIntegration_spcWS_spcWrapper_Execute_Input>

      <asi:_XMLMessage>

        <SiebelMessage ErrorMessage="INVALID STATE/COUNTRY" ErrorCode="1020" MsgType="Cr" IntObjectFormat="Siebel Hierarchical" IntObjectName="HS" MessageType="Integration">

          <ListOfServiceProvider>

            <ServiceProvider>

              <Id>1</Id>

              <SAPVendorNumber/>

            </ServiceProvider>

          </ListOfServiceProvider>

        </SiebelMessage>

      </asi:_XMLMessage>

    </asi:HS1_spcGeneric_spcInbound_spcIntegration_spcWS_spcWrapper_Execute_Input>

  </soapenv:Body>

</SOAP:Envelope>

Expectation is to have the XML content in present in <asi:_XMLMessage> parameters with escape characters as shown below:


<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" xmlns:asi="http://siebel.com/asi/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">

  <soapenv:Header>

    <wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/07/secext" soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="0">

      <wsse:UsernameToken>

        <wsse:Username>O</wsse:Username>

        <wsse:Password Type="wsse:PasswordText">O</wsse:Password>

      </wsse:UsernameToken>

    </wsse:Security>

  </soapenv:Header>

  <soapenv:Body>

    <asi:HS1_spcGeneric_spcInbound_spcIntegration_spcWS_spcWrapper_Execute_Input>

      <asi:_XMLMessage>

        &lt;SiebelMessage ErrorMessage=&quot;INVALID STATE/COUNTRY&quot; ErrorCode=&quot;1020&quot; MsgType=&quot;Cr&quot; IntObjectFormat=&quot;Siebel Hierarchical&quot; IntObjectName=&quot;HS&quot; MessageType=&quot;Integration&quot;&gt;

          &lt;ListOfServiceProvider&gt;

            &lt;ServiceProvider&gt;

              &lt;Id&gt;1&lt;/Id&gt;

              &lt;SAPVendorNumber/&gt;

            &lt;/ServiceProvider&gt;

          &lt;/ListOfServiceProvider&gt;

        &lt;/SiebelMessage&gt;

      </asi:_XMLMessage>

    </asi:HS1_spcGeneric_spcInbound_spcIntegration_spcWS_spcWrapper_Execute_Input>

  </soapenv:Body>

</SOAP:Envelope>

Please suggest if there is a way to convert the unescaped characters into escape characters by modifying in the same above XSL code?

Thanks.

Regards,

AJ

Accepted Solutions (1)

Accepted Solutions (1)

iaki_vila
Active Contributor
0 Kudos

Hi AJ,

With this XSLT (Converting XML to escaped text in XSLT - Stack Overflow😞


<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" xmlns:asi="http://siebel.com/asi/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">

    <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>

    <xsl:strip-space elements="*"/>

    <xsl:template match="/">

        <SOAP:Envelope>

            <soapenv:Header>

                <wsse:Security soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="0" xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/07/secext">

                    <wsse:UsernameToken>

                        <wsse:Username>O</wsse:Username>

                        <wsse:Password Type="wsse:PasswordText">O</wsse:Password>

                    </wsse:UsernameToken>

                </wsse:Security>

            </soapenv:Header>

            <soapenv:Body>

                <asi:HS1_spcGeneric_spcInbound_spcIntegration_spcWS_spcWrapper_Execute_Input>

                    <asi:_XMLMessage>

                        <xsl:apply-templates select="." mode="escape"/>

                    </asi:_XMLMessage>

                </asi:HS1_spcGeneric_spcInbound_spcIntegration_spcWS_spcWrapper_Execute_Input>

            </soapenv:Body>

        </SOAP:Envelope>

    </xsl:template>

    <xsl:template match="*" mode="escape">

        <!-- Begin opening tag -->

        <xsl:text>&lt;</xsl:text>

        <xsl:value-of select="name()"/>

        <!-- Namespaces -->

        <xsl:for-each select="namespace::*">

            <xsl:text> xmlns</xsl:text>

            <xsl:if test="name() != ''">

                <xsl:text>:</xsl:text>

                <xsl:value-of select="name()"/>

            </xsl:if>

            <xsl:text>='</xsl:text>

            <xsl:call-template name="escape-xml">

                <xsl:with-param name="text" select="."/>

            </xsl:call-template>

            <xsl:text>'</xsl:text>

        </xsl:for-each>

        <!-- Attributes -->

        <xsl:for-each select="@*">

            <xsl:text> </xsl:text>

            <xsl:value-of select="name()"/>

            <xsl:text>='</xsl:text>

            <xsl:call-template name="escape-xml">

                <xsl:with-param name="text" select="."/>

            </xsl:call-template>

            <xsl:text>'</xsl:text>

        </xsl:for-each>

        <!-- End opening tag -->

        <xsl:text>&gt;</xsl:text>

        <!-- Content (child elements, text nodes, and PIs) -->

        <xsl:apply-templates select="node()" mode="escape"/>

        <!-- Closing tag -->

        <xsl:text>&lt;/</xsl:text>

        <xsl:value-of select="name()"/>

        <xsl:text>&gt;</xsl:text>

    </xsl:template>

    <xsl:template match="text()" mode="escape">

        <xsl:call-template name="escape-xml">

            <xsl:with-param name="text" select="."/>

        </xsl:call-template>

    </xsl:template>

    <xsl:template match="processing-instruction()" mode="escape">

        <xsl:text>&lt;?</xsl:text>

        <xsl:value-of select="name()"/>

        <xsl:text> </xsl:text>

        <xsl:call-template name="escape-xml">

            <xsl:with-param name="text" select="."/>

        </xsl:call-template>

        <xsl:text>?&gt;</xsl:text>

    </xsl:template>

    <xsl:template name="escape-xml">

        <xsl:param name="text"/>

        <xsl:if test="$text != ''">

            <xsl:variable name="head" select="substring($text, 1, 1)"/>

            <xsl:variable name="tail" select="substring($text, 2)"/>

            <xsl:choose>

                <xsl:when test="$head = '&amp;'">&amp;amp;</xsl:when>

                <xsl:when test="$head = '&lt;'">&amp;lt;</xsl:when>

                <xsl:when test="$head = '&gt;'">&amp;gt;</xsl:when>

                <xsl:when test="$head = '&quot;'">&amp;quot;</xsl:when>

                <xsl:when test="$head = &quot;&apos;&quot;">&amp;apos;</xsl:when>

                <xsl:otherwise>

                    <xsl:value-of select="$head"/>

                </xsl:otherwise>

            </xsl:choose>

            <xsl:call-template name="escape-xml">

                <xsl:with-param name="text" select="$tail"/>

            </xsl:call-template>

        </xsl:if>

    </xsl:template>

</xsl:stylesheet>

You will get this:


<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" xmlns:asi="http://siebel.com/asi/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">

    <soapenv:Header>

        <wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/07/secext" soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="0">

            <wsse:UsernameToken>

                <wsse:Username>O</wsse:Username>

                <wsse:Password Type="wsse:PasswordText">O</wsse:Password>

            </wsse:UsernameToken>

        </wsse:Security>

    </soapenv:Header>

    <soapenv:Body>

        <asi:HS1_spcGeneric_spcInbound_spcIntegration_spcWS_spcWrapper_Execute_Input>

            <asi:_XMLMessage>&lt;SiebelMessage xmlns:xml='http://www.w3.org/XML/1998/namespace' ErrorMessage='INVALID STATE/COUNTRY' ErrorCode='1020' MsgType='Cr' IntObjectFormat='Siebel Hierarchical' IntObjectName='HS' MessageType='Integration'&gt;&lt;ListOfServiceProvider xmlns:xml='http://www.w3.org/XML/1998/namespace'><ServiceProvider xmlns:xml='http://www.w3.org/XML/1998/namespace'><Id xmlns:xml='http://www.w3.org/XML/1998/namespace'>1</Id><SAPVendorNumber xmlns:xml='http://www.w3.org/XML/1998/namespace'></SAPVendorNumber></ServiceProvider></ListOfServiceProvider></...</asi:_XMLMessage>

        </asi:HS1_spcGeneric_spcInbound_spcIntegration_spcWS_spcWrapper_Execute_Input>

    </soapenv:Body>

</SOAP:Envelope>

Regards.

Former Member
0 Kudos

Hi Inaki,

It worked like a charm, thanks a lot for providing the code. Can you help me with a XSLT code which can convert the output back into below XML?

  • <?xml version="1.0" encoding="UTF-8"?> 
  • <SiebelMessage ErrorMessage="INVALID STATE/COUNTRY" ErrorCode="1020" MsgType="Cr" IntObjectFormat="Siebel Hierarchical" IntObjectName="HS" MessageType="Integration"> 
  • <ListOfServiceProvider> 
  • <ServiceProvider> 
  • <Id>1</Id> 
  • <SAPVendorNumber/> 
  • </ServiceProvider> 
  • </ListOfServiceProvider> 
  • </SiebelMessage> 

Regards,

AJ

iaki_vila
Active Contributor
0 Kudos

Hi AJ,

Try with this XSLT:


<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:asi="http://siebel.com/asi/">

    <xsl:template match="/">

        <xsl:value-of select="//asi:_XMLMessage" disable-output-escaping="yes"/>

    </xsl:template>

</xsl:stylesheet>

Regards.

Former Member
0 Kudos

Hi Inaki,

Unfortunately, XML generated with escape characters did not work well, can you help me in generating the XML with escape characters for below input message and compare it with the output message as shown below:

Input Message:


<?xml version="1.0" encoding="UTF-8"?>

<SiebelMessage MessageType="Integration Object" IntObjectName="HS1 Financial IO" IntObjectFormat="Siebel Hierarchical" MsgType="Create" ErrorCode="0">

  <ListOfFinancialHeader>

  <FinancialHeader>

  <Id>1</Id>

  <ListOfFinancialLineItems>

  <FinancialLineItem>

  <Id>1</Id>

  <PurchaseOrderNumber>4444444444</PurchaseOrderNumber>

  </FinancialLineItem>

  </ListOfFinancialLineItems>

  </FinancialHeader>

  </ListOfFinancialHeader>

</SiebelMessage>

Output message with escape characters "SOAP Wrapper remain same, its just that the XML message in <asi:_XMLMessage> tag needs to have escape characters as shown below: <asi:_XMLMessage>


<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" xmlns:asi="http://siebel.com/asi/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">

  <soapenv:Header>

    <wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/07/secext" soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="0">

      <wsse:UsernameToken>

        <wsse:Username>O</wsse:Username>

        <wsse:Password Type="wsse:PasswordText">O</wsse:Password>

      </wsse:UsernameToken>

    </wsse:Security>

  </soapenv:Header>

  <soapenv:Body>

    <asi:HS1_spcGeneric_spcInbound_spcIntegration_spcWS_spcWrapper_Execute_Input>

      <asi:_XMLMessage>&lt;SiebelMessage MessageType=&quot;Integration Object&quot; IntObjectName=&quot;HS1 Financial IO&quot; IntObjectFormat=&quot;Siebel Hierarchical&quot; MsgType=&quot;Create&quot; ErrorCode=&quot;0&quot;&gt;

  &lt;ListOfFinancialHeader&gt;

  &lt;FinancialHeader&gt;

  &lt;Id&gt;1&lt;/Id&gt;

  &lt;ListOfFinancialLineItems&gt;

  &lt;FinancialLineItem&gt;

  &lt;Id&gt;1&lt;/Id&gt;

  &lt;PurchaseOrderNumber&gt;4444444444&lt;/PurchaseOrderNumber&gt;

  &lt;/FinancialLineItem&gt;

  &lt;/ListOfFinancialLineItems&gt;

  &lt;/FinancialHeader&gt;

  &lt;/ListOfFinancialHeader&gt;

&lt;/SiebelMessage&gt;</asi:_XMLMessage>

    </asi:HS1_spcGeneric_spcInbound_spcIntegration_spcWS_spcWrapper_Execute_Input>

  </soapenv:Body>

</SOAP:Envelope>

Appreciate if you can help me in getting the desired outcome using the XSLT code. Thanks.

Regards,

AJ

Answers (0)