Removing Declarations in XML payloads through XML Modifier


For the scenarios having XML declaration and document type declarations (DTD) in the incoming payload, we generally implement a separate step by writing an XSL / Groovy script to remove these declarations for proper schema. Instead of writing this script we can directly make use of the palette function “XML Modifier” directly to remove these declarations/namespaces. Let’s explore this palette function in detail.

XSL script to remove XML declaration:

<xsl:stylesheet version="1.0" xmlns:xsl=""> <xsl:output method="xml" omit-xml-declaration="yes" /> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> </xsl:stylesheet>

Setting up XML Modifier:

Go to message transformers, select XML modifier:



Let us consider a scenario to understand the use case of XML Modifier using the below sample Integration flow:

  1. This is a timer-based interface which runs once on our ad hoc requirements.
  2.  I have set the below sample payload as the body through the content modifier.


<?xml version="1.0" encoding="UTF-8"?> // XML Declaration <!DOCTYPE note SYSTEM "note.dtd"> // DTD <persondetails> <name>ABCD</name> <city>XYZ</city> <contact>98982028211</contact> <DateOfBirth>1996/07/31</DateOfBirth> <education>PG</education> </persondetails>

3.a) Remove XML declaration from payload.

In XML Modifier processing, select the checkbox “Remove XML Declaration”.

Output of the above deployed Integration is logged as an attachment using Groovy Step.

<!DOCTYPE note SYSTEM "note.dtd"> <persondetails> <name>ABCD</name> <city>XYZ</city> <contact>98982028211</contact> <DateOfBirth>1996/07/31</DateOfBirth> <education>PG</education> </persondetails>

3.b) Remove XML Declarations and DTD from payload.

In XML Modifier processing, select both the checkboxes to see the following output –

Output Payload

<persondetails> <name>ABCD</name> <city>XYZ</city> <contact>98982028211</contact> <DateOfBirth>1996/07/31</DateOfBirth> <education>PG</education> </persondetails>

Use Case:

  • In scenarios having multiple incoming payloads (Example: payloads from more than one request reply) we need to remove XML declarations of the individual payloads for successful mapping (multi mapping with namespaces) where XML Modifier can prevent the usage of XSLTs.
  • In SAP CPI, DTDs can cause message to fail due to enhanced security features. It is important to remove these declarations which can be done by this palette function.

I hope, you can benefit from the palette function presented in this blog post.

In case of questions or feedback, please feel free to comment on this blog.