cancel
Showing results for 
Search instead for 
Did you mean: 

Email Receiver converting < to <

Former Member
0 Kudos

Hi, we have an outbound email setup which is converting an XML payload to an attachment.

Sometime after the mapping it is converting some of our escaped content to a different format and it is causing trouble.

In the email receiver adapter we are running the message through XMLAnonymizer also.

I can confirm the Integration Engine Mapping is leaving it untouched.

How can I get the adapter / beans to preserve &lt and &gt instead of codes &#60 and &#61?

Many thanks,

Aaron

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Thanks again Baskar, feel like I'm getting very close now, but I'm not familiar with this XSLT format. I'm trying to learn it but in the mean time if anyone knows the answer I will appreciate it.

I have source structure like:

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

<nfeProc xmlns="http://www.portalfiscal.inf.br/nfe">

...

<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">

....

</Signature>

....

</nfeProc>

The PI mapping is changing it to:

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

<ns0:nfeProc xmlns:ns0="http://www.portalfiscal.inf.br/nfe">

...

<ns1:Signature xmlns:ns1="http://www.w3.org/2000/09/xmldsig#">

....

</ns1:Signature>

....

</ns0:nfeProc>

This is invalidating the digital signature. XML Anonymizer was working perfectly for cleaning up these namespace prefixes but it has an unintended consequence of changing some characters in a free form CDATA string from < to & #60 ; notation.

So I tried to use this XSLT instead of XMLAnonymizer which gets very close, but it is removing the xml namespace of the Signature...which I need.

XSL:

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

<xsl:stylesheet version="1.0"

          xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

          xmlns:ns0="http://www.portalfiscal.inf.br/nfe"

          xmlns="http://www.portalfiscal.inf.br/nfe"

          xmlns:ns1="http://www.w3.org/2000/09/xmldsig#"

>

 

<xsl:output method="xml" indent="no"/>

  <xsl:template match="ns0:*|ns1:*">

    <xsl:element name="{local-name()}">

      <xsl:apply-templates select="@*|node()"/>

    </xsl:element>

</xsl:template>

  <xsl:template match="@*|node()">

    <xsl:copy>

      <xsl:apply-templates select="@*|node()"/>

    </xsl:copy>

</xsl:template>

</xsl:stylesheet>

Result:

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

<nfeProc xmlns="http://www.portalfiscal.inf.br/nfe">

...

<Signature>

....

</Signature>

....

</nfeProc>

The main problem now, this is removing the " xmlns="http://www.w3.org/2000/09/xmldsig#" from Signature element. Also this whole XSL approach seems to be combining some elements like:

<Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"></Transform>

gets shortened to:

<Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>

I know this logically equivalent but I would rather preserve everything in the original XML as is. There must be an easier way!

All I really want to do in this whole scenario is send an XML payload unchanged as an email attachment. I must use a mapping to set dynamic configuration variables of mail adapter. Mapping is introducing namespace prefix changes to XML. Then trying to undo those, XML Anonymizer introduced further changes to freeform CDATA XML. Seems the XSLT approach is also causing side effects.

Former Member
0 Kudos

Final solution, add XSLT mappings to the end of the relevant Operation Mapping.

1) Get rid of ns0 with first XSLT map"

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

<xsl:stylesheet version="1.0"

          xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

          xmlns:ns0="[-put namespace you want to use here-]"

          xmlns="[-put namespace you want to use here-]"

>

<xsl:output method="xml" indent="no"/>

<xsl:template match="ns0:*">

    <xsl:element name="{local-name()}">

      <xsl:apply-templates select="@*|node()"/>

    </xsl:element>

</xsl:template>

<xsl:template match="@*|node()">

    <xsl:copy>

      <xsl:apply-templates select="@*|node()"/>

    </xsl:copy>

</xsl:template>

</xsl:stylesheet>

2) Do similar with any other PI namespace you want to replace like ns1

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

- <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns1="[second namespace to keep]" xmlns="[second namespace to keep]">
<xsl:output method="xml" indent="no" />
  <xsl:template match="ns1:*">
  <xsl:element name="{local-name()}">
<xsl:apply-templates select="@*|node()" />

</xsl:element>

</xsl:template>

  <xsl:template match="@*|node()">
  <xsl:copy>
<xsl:apply-templates select="@*|node()" />

</xsl:copy>

</xsl:template>

</xsl:stylesheet>

3) XMLAnonymizer was no longer needed in our case.

Answers (2)

Answers (2)

Former Member
0 Kudos

Sorry guys, I found this issue isn't with the email adapter itself. When I take the XML Anonymizer bean out of the loop the issue goes away.

However, I still need to get rid of the extra namespaces PI is adding. Any more ideas considering this?

baskar_gopalakrishnan2
Active Contributor
0 Kudos

What do you do with XMLAnonymizer bean ?  Are you removing extra namespace?  Are you changing the encoding of the message using anonymizer.encoding?  The other simplest idea is to use xslt mapping to get rid of the extra namespace.  This is an easier solution.

You might also check this blog and the questions below...

http://scn.sap.com/people/stefan.grube/blog/2007/02/02/remove-namespace-prefix-or-change-xml-encodin...

Former Member
0 Kudos

Thats right Baskar, I'm using XML Anonymizer bean to get rid of extra namespaces. I haven't intentionally changed any encoding using that parameter. It is working correctly for removing the namespaces but one segment sometimes gets this extra CDATA xml string and it is getting treated differently here in PI.

I've never used an XSLT mapping before but I may give that a try instead of the bean.

Former Member
0 Kudos

So this example XSLT is working to wipe out all namespaces... I want to only get rid of "ns0" prefix for now. Any help paring it down is appreciated!

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" indent="no"/>

<xsl:template match="/|comment()|processing-instruction()">

    <xsl:copy>

      <xsl:apply-templates/>

    </xsl:copy>

</xsl:template>

<xsl:template match="*">

    <xsl:element name="{local-name()}">

      <xsl:apply-templates select="@*|node()"/>

    </xsl:element>

</xsl:template>

<xsl:template match="@*">

    <xsl:attribute name="{local-name()}">

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

    </xsl:attribute>

</xsl:template>

</xsl:stylesheet>

baskar_gopalakrishnan2
Active Contributor
0 Kudos

Please try this thread way... Basically I don't know your structure....

http://stackoverflow.com/questions/16810039/how-to-remove-namespace-prefix-leaving-namespace-value-x...

You have to use your namespace prefix accordingly in the code. Example:( here it is given as xmlns:xenc ) (xenc is prefix)

baskar_gopalakrishnan2
Active Contributor
0 Kudos

Please check whether the editor you view the attachment has issue. Just to make sure , you can try with different editor to view the attachment.Also check whether content encoding type is changed in your bean level (if any) instead UTF-8

Former Member
0 Kudos

Hi Baskar, it is not the editor. I can see clearly in notepad from the attachment the conversion must be happening in the Adapter Engine or beans.

Can you give a hint about setting encoding type in the mail adapter for attachments? I don't see any settings which would be changing this.

baskar_gopalakrishnan2
Active Contributor
0 Kudos

You might want to check this SAP document and suggested note for the content type encoding setup in mail adapter

http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/502991a2-45d9-2910-d99f-8aba5d79f...