cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

CPI Message mapping is it possible to retain empty XML elements on the target XML?

Raj_Nallaguntla
Explorer
0 Kudos
4,242

Hi All,

checking if its possible to send empty xml elements as for eg <ABC/> ( empty tag) on the target xml,

XML file generated from CPI MM does not include the empty tag when no value found on the source.

I understand that no value of sending empty xml element on the target

but have specific requirement to match the legacy xml file which includes empty elements . any idea or pointers ?

Thanks,

Accepted Solutions (0)

Answers (5)

Answers (5)

Sriprasadsbhat
Active Contributor

Hello Raj,

Make sure each and every field mapping have map with default to get start tag/end tag irrespective of whether it has data or not.Also you can have early one to one mapping having for every field map with default to make sure you get the required tags.

Regards,

Sriprasad Shivaram Bhat

yatanveersingh
Active Participant

HI Raj,

In case the value is not coming you can use function MapWithDefault in message mapping.

Yatan

Raj_Nallaguntla
Explorer
0 Kudos

Hi Yatan,

I tried the MapWithDefault but it expects some value as default value which in my case is blank

so it will not work unless there is a way to pass just blank and not Null.?

Also I noticed if the element is included in source XML then the target retain the empty tag as expected

Source <ABC></ABC>

target <ABC/>

only if the source does not contain the tag altogether then it skips on the target totally.

Thanks

Raj

RAAMS
Explorer
0 Kudos

<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="node()|@*"> <xsl:if test="normalize-space(string(.)) != ''"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:if> </xsl:template> </xsl:stylesheet>

Raj_Nallaguntla
Explorer
0 Kudos

further update on this if any one come across similar requirement this may help ...

if target node needs to be created even if source xml tag does not exists on the source file ( common in idoc-xml to non-idoc-xml scenarios )

use node function "exists" to check if the source tag exists or not based on the outcome of the node function ... we can use "if" to achieve desired results. for eg if the source tag does not exists assign default value.

Regards,

Raj Nallaguntla

Raj_Nallaguntla
Explorer
0 Kudos

Thank you Yetan and Sriprasad for your inputs.

Yes I agree if we need the start tag/end tag will need default value mapped for those fields.

In my case though I need only empty tag <ENDTAG/> ( defined as xstring )on the target.

What I noticed further checking on this ... if that helps others

When the source tag for eg <STARTTAG></STARTTAG> exists on the source xml file that is mapped to <ENDTAG> then CPI message mapping by default includes <ENDTAG/> empty tag in the target xml

if the source tag does not exists then it is skipped totally on the target XML.