cancel
Showing results for 
Search instead for 
Did you mean: 

remove the empty tags from xml

former_member234749
Participant
0 Kudos

Hi All,

I have a scenario Proxy to File. I am getting the empty tags in the inbound paylod for those fileds are not having values. I just want to remove the empty tags while generating the XML file at receiver side.

There is no mapping for this. I have put the occrance of each filed 1 :1. Can we restrict the empty tags to change the the occurance to 0:1?

or is there any possibility to remove the empty tags at ECC or Do we have to use XSLT mapping for this?

Thanks

Accepted Solutions (0)

Answers (4)

Answers (4)

JaySchwendemann
Active Contributor
0 Kudos

SAP PI wrote:

...

There is no mapping for this. I have put the occrance of each filed 1 :1. Can we restrict the empty tags to change the the occurance to 0:1?

Hi,

do you mean that you currently don't have a message mapping? You probably would need a message mapping to get rid of any empty tags. You could then use already given solutions (xslt mapping / message mapping with changing fields to optional).

HTH

cheers

ambrish_mishra
Active Contributor
0 Kudos

Hi,

For the fields you don't want empty tags, make them optional both at source and target and map them direct.

Ambrish

peter_wallner2
Active Contributor
0 Kudos

Hello,

If you go with XSLT you could use this which will get rid of empty tags (nodes, attributes, comments and processing instructions):



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

<xsl:template match=
   
"*[not(@*|*|comment()|processing-instruction())
     and normalize-space()=''
      ]"
/>

I hope this helps.

Best regards,

Peter

Former Member
0 Kudos

Hi Peter,

What do you mean with XSLT? Where can I write that code? Could you please tell more about it.

azharshaikh
Active Contributor
0 Kudos

Hi,

Yes you need to create .xls file for the abv code xslt and Import in Imported Archive in .zip format. You need to use this IA in ur Operation Mapping.

My few cents:

You can achieve this using Std Graphical mapping  (easy to maintain & performance efficient) as suggested in abv posts (instead of XSLT)

Regards,

Azhar

Former Member
0 Kudos

Thanks Azhar,

I got it working using XSLT. But, like you said, it is not really efficient. It is taking too long. Can you give me a hint on what function to use in Graphical mapping? My problem is that in the source message I have occurrence 0 to unbound.

Thanks for your help.

former_member184720
Active Contributor
0 Kudos

>>>Can you give me a hint on what function to use in Graphical mapping?


Make sure that your target field occurrence is 0..1

source field -> length(text) ->greater(arthritic) ->"0"(constant) -> ifwithoutelse(boolean) -> target field

Muniyappan
Active Contributor
0 Kudos

Hi,

1. you can remove the empty tag putting condition and using createif function.

this will make sense only for occurrence 0..1.

2. if tag is coming ,it has empty value and occurrence is 1..1. then removing tag will cause mapping error since it is mandatory field.

you can make occurrence 0..1 and if tag is empty valued you can removing it using createif.

Regards,

Muniyappan.